Removing a several JSPs that were part of the N3 editing. These should no longer be used. NIHVIVO-2349
This commit is contained in:
parent
61fbcd9c58
commit
5f2db5f824
12 changed files with 0 additions and 2090 deletions
|
@ -1,87 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Property" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
|
||||||
<%@ page import="java.util.ArrayList" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.Log" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
|
||||||
<%!
|
|
||||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.dashboardPropsList.jsp");
|
|
||||||
%>
|
|
||||||
|
|
||||||
<c:set var='entity' value='${requestScope.entity}'/><%-- just moving this into page scope for easy use --%>
|
|
||||||
<%
|
|
||||||
log.debug("Starting dashboardPropsList.jsp");
|
|
||||||
|
|
||||||
// The goal here is to retrieve a list of object and data properties appropriate for the vclass
|
|
||||||
// of the individual, by property group, and sorted the same way they would be in the public interface
|
|
||||||
|
|
||||||
Individual subject = (Individual) request.getAttribute("entity");
|
|
||||||
if (subject==null) {
|
|
||||||
throw new Error("Subject individual must be in request scope for dashboardPropsList.jsp");
|
|
||||||
}
|
|
||||||
|
|
||||||
String defaultGroupName=null;
|
|
||||||
String unassignedGroupName = (String) request.getAttribute("unassignedPropsGroupName");
|
|
||||||
if (unassignedGroupName != null && unassignedGroupName.length()>0) {
|
|
||||||
defaultGroupName = unassignedGroupName;
|
|
||||||
log.debug("found temp group attribute \""+unassignedGroupName+"\" for unassigned properties");
|
|
||||||
}
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
PropertyGroupDao pgDao = wdf.getPropertyGroupDao();
|
|
||||||
ArrayList<PropertyGroup> groupsList = (ArrayList) request.getAttribute("groupsList");
|
|
||||||
if (groupsList != null) {
|
|
||||||
if (groupsList.size()>1) {%>
|
|
||||||
<ul id="propGroupNav">
|
|
||||||
<% for (PropertyGroup g : groupsList) { %>
|
|
||||||
<li><h2><a href="#<%=g.getLocalName()%>" title="<%=g.getName()%>"><%=g.getName()%></a></h2></li>
|
|
||||||
<% }%>
|
|
||||||
</ul>
|
|
||||||
<% }
|
|
||||||
} else {
|
|
||||||
ArrayList<Property> mergedList = (ArrayList) request.getAttribute("dashboardPropertyList");
|
|
||||||
if (mergedList!=null) {
|
|
||||||
String lastGroupName = null;
|
|
||||||
int groupCount=0;%>
|
|
||||||
<ul id="propGroupNav">
|
|
||||||
<% for (Property p : mergedList) {
|
|
||||||
String groupName = defaultGroupName; // may be null
|
|
||||||
String groupLocalName = defaultGroupName; // may be null
|
|
||||||
String groupPublicDescription=null;
|
|
||||||
String propertyLocalName = p.getLocalName() == null ? "unspecified" : p.getLocalName();
|
|
||||||
String openingGroupLocalName = (String) request.getParameter("curgroup");
|
|
||||||
if (p.getGroupURI()!=null) {
|
|
||||||
PropertyGroup pg = pgDao.getGroupByURI(p.getGroupURI());
|
|
||||||
if (pg != null) {
|
|
||||||
groupName=pg.getName();
|
|
||||||
groupLocalName=pg.getLocalName();
|
|
||||||
groupPublicDescription=pg.getPublicDescription();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (groupName != null && !groupName.equals(lastGroupName)) {
|
|
||||||
lastGroupName=groupName;
|
|
||||||
++groupCount;
|
|
||||||
|
|
||||||
if (openingGroupLocalName == null || openingGroupLocalName.equals("")) {
|
|
||||||
openingGroupLocalName = groupLocalName;
|
|
||||||
}
|
|
||||||
if (openingGroupLocalName.equals(groupLocalName)) {%>
|
|
||||||
<li class="currentCat"><h2><a href="#<%=groupLocalName%>" title="<%=groupName%>"><%=groupName%></a></h2></li>
|
|
||||||
<% } else { %>
|
|
||||||
<li><h2><a href="#<%=groupLocalName%>" title="<%=groupName%>"><%=groupName%></a></h2></li>
|
|
||||||
<% }
|
|
||||||
}
|
|
||||||
}%>
|
|
||||||
</ul>
|
|
||||||
<% }
|
|
||||||
}%>
|
|
||||||
|
|
|
@ -1,182 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
|
||||||
<%@ 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.configuration.EditConfiguration" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash" %>
|
|
||||||
<%@ 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.dao.VitroVocabulary" %>
|
|
||||||
<%@ page import="java.util.HashMap" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.Log" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
|
||||||
|
|
||||||
<%
|
|
||||||
//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");
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousPages" %>
|
|
||||||
<% request.setAttribute("requestedActions", new UseMiscellaneousPages()); %>
|
|
||||||
<vitro:confirmAuthorization />
|
|
||||||
|
|
||||||
<%
|
|
||||||
//Check if special model, in which case forward
|
|
||||||
if(request.getParameter("switchToDisplayModel") != null) {
|
|
||||||
//forward to Edit Request Dispatch Controller
|
|
||||||
String queryString = request.getQueryString();
|
|
||||||
response.sendRedirect(request.getContextPath() + "/editRequestDispatch?" + queryString);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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";
|
|
||||||
final String DEFAULT_ERROR_FORM = "error.jsp";
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
if( EditConfiguration.getEditKey( vreq ) == null ){
|
|
||||||
vreq.setAttribute("editKey",EditConfiguration.newEditKey(session));
|
|
||||||
}else{
|
|
||||||
vreq.setAttribute("editKey", EditConfiguration.getEditKey( vreq ));
|
|
||||||
}
|
|
||||||
|
|
||||||
//set title to Edit to maintain functionality from 1.1.1 and avoid updates to Selenium tests
|
|
||||||
request.setAttribute("title","Edit");
|
|
||||||
|
|
||||||
String subjectUri = vreq.getParameter("subjectUri");
|
|
||||||
String predicateUri = vreq.getParameter("predicateUri");
|
|
||||||
String formParam = vreq.getParameter("editForm");
|
|
||||||
String command = vreq.getParameter("cmd");
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since we have the URIs let's put the individual, data property, and optional data property statement in the request
|
|
||||||
vreq.setAttribute("subjectUri", subjectUri);
|
|
||||||
vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri));
|
|
||||||
vreq.setAttribute("predicateUri", predicateUri);
|
|
||||||
vreq.setAttribute("predicateUriJson", MiscWebUtils.escape(predicateUri));
|
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
|
|
||||||
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
|
|
||||||
if( subject == null ) {
|
|
||||||
log.error("Could not find subject Individual '"+subjectUri+"' in model");
|
|
||||||
throw new Error("editDatapropStmtRequestDispatch.jsp: Could not find subject Individual in model: '" + subjectUri + "'");
|
|
||||||
}
|
|
||||||
vreq.setAttribute("subject", subject);
|
|
||||||
|
|
||||||
WebappDaoFactory unfilteredWdf = vreq.getUnfilteredWebappDaoFactory();
|
|
||||||
DataProperty dataproperty = unfilteredWdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
|
||||||
if( dataproperty == null) {
|
|
||||||
// No dataproperty will be returned for rdfs:label, but we shouldn't throw an error.
|
|
||||||
// This is controlled by the Jena layer, so we can't change the behavior.
|
|
||||||
if (! predicateUri.equals(VitroVocabulary.LABEL)) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
|
||||||
dps = RdfLiteralHash.getPropertyStmtByHash(subject.getURI(), predicateUri, dataHash, model);
|
|
||||||
|
|
||||||
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() ){
|
|
||||||
if (dataproperty != null) {
|
|
||||||
log.debug("predicate for DataProperty from request is " + dataproperty.getURI() + " with rangeDatatypeUri of '" + dataproperty.getRangeDatatypeURI() + "'");
|
|
||||||
}
|
|
||||||
if( dps == null )
|
|
||||||
log.debug("no existing DataPropertyStatement statement was found, making a new statemet");
|
|
||||||
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";
|
|
||||||
msg += " hash of this stmt: " + RdfLiteralHash.makeRdfLiteralHash(dps);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
String form = null;
|
|
||||||
if (formParam != null) {
|
|
||||||
form = formParam;
|
|
||||||
}
|
|
||||||
else if (predicateUri.equals(VitroVocabulary.LABEL)) { // dataproperty is null here
|
|
||||||
form = "rdfsLabelForm.jsp";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
form = dataproperty.getCustomEntryForm();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vreq.setAttribute("form", form);
|
|
||||||
|
|
||||||
if( session.getAttribute("requestedFromEntity") == null ) {
|
|
||||||
session.setAttribute("requestedFromEntity", subjectUri );
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
<jsp:forward page="/edit/forms/${form}" />
|
|
|
@ -1,279 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@page import="java.util.Map"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.JspToGeneratorMapping"%>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
|
||||||
<%@ 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.configuration.EditConfiguration" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
|
||||||
<%@ page import="java.util.HashMap" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.Log" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
|
||||||
<%@ page errorPage="/error.jsp" %>
|
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
|
||||||
|
|
||||||
<%!
|
|
||||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editRequestDispatch.jsp");
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousPages" %>
|
|
||||||
<% request.setAttribute("requestedActions", new UseMiscellaneousPages()); %>
|
|
||||||
<vitro:confirmAuthorization />
|
|
||||||
|
|
||||||
<%
|
|
||||||
|
|
||||||
//Check if special model, in which case forward
|
|
||||||
if(request.getParameter("switchToDisplayModel") != null) {
|
|
||||||
//forward to Edit Request Dispatch Controller
|
|
||||||
String queryString = request.getQueryString();
|
|
||||||
//Instead of edit request which is what we'll do later, here we'll forward to Menu Management Controller
|
|
||||||
response.sendRedirect(request.getContextPath() + "/editDisplayModel?" + queryString);
|
|
||||||
}
|
|
||||||
|
|
||||||
//If you find the parameter for testing the old edit, go ahead with the rest of the form
|
|
||||||
//otherwise forward immediately to the new edit request dispatch controller
|
|
||||||
String oldEdit = request.getParameter("oldEdit");
|
|
||||||
if(oldEdit == null) {
|
|
||||||
String queryString = request.getQueryString();
|
|
||||||
response.sendRedirect(
|
|
||||||
request.getContextPath() +
|
|
||||||
"/editRequestDispatch?" +
|
|
||||||
queryString);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, and predicateUriJson in request.
|
|
||||||
Also get the Individual for the subjectUri and put it in the request scope.
|
|
||||||
|
|
||||||
If objectUri is set as a http parameter, then set objectUri and objectUriJson in request, also get the
|
|
||||||
Individual for the objectUri and put it in the request.
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
Parameters:
|
|
||||||
subjectUri
|
|
||||||
predicateUri
|
|
||||||
objectUri (optional)
|
|
||||||
cmd (optional)
|
|
||||||
typeOfNew (optional)
|
|
||||||
************************************** */
|
|
||||||
|
|
||||||
final String DEFAULT_OBJ_FORM = "defaultObjPropForm.jsp";
|
|
||||||
final String DEFAULT_ERROR_FORM = "error.jsp";
|
|
||||||
final String DEFAULT_ADD_INDIVIDUAL = "defaultAddMissingIndividualForm.jsp";
|
|
||||||
|
|
||||||
String editKey = (EditConfiguration.getEditKey(request) == null)
|
|
||||||
? EditConfiguration.newEditKey(session)
|
|
||||||
: EditConfiguration.getEditKey(request);
|
|
||||||
request.setAttribute("editKey", editKey);
|
|
||||||
|
|
||||||
//set title to Edit to maintain functionality from 1.1.1 and avoid updates to Selenium tests
|
|
||||||
request.setAttribute("title","Edit");
|
|
||||||
|
|
||||||
// set the referrer URL, if available
|
|
||||||
setEditReferer(editKey, request.getHeader("Referer"), request.getSession());
|
|
||||||
|
|
||||||
/* Figure out what type of edit is being requested,
|
|
||||||
setup for that type of edit OR forward to some
|
|
||||||
thing that can do the setup */
|
|
||||||
|
|
||||||
String subjectUri = request.getParameter("subjectUri");
|
|
||||||
String predicateUri = request.getParameter("predicateUri");
|
|
||||||
String formParam = request.getParameter("editform");
|
|
||||||
String command = request.getParameter("cmd");
|
|
||||||
String typeOfNew = request.getParameter("typeOfNew");
|
|
||||||
|
|
||||||
//If there is no specified editForm then the subjectURI and the predicate
|
|
||||||
//are needed to determine which form to use for this edit.
|
|
||||||
if (formParam == null || "".equals(formParam)) {
|
|
||||||
if (subjectUri == null || subjectUri.trim().length() == 0)
|
|
||||||
throw new Error(
|
|
||||||
"subjectUri was empty, it is required by editRequestDispatch");
|
|
||||||
if ((predicateUri == null || predicateUri.trim().length() == 0)
|
|
||||||
&& (formParam == null || formParam.trim().length() == 0)) {
|
|
||||||
throw new Error(
|
|
||||||
"No form was specified, since both predicateUri and"
|
|
||||||
+ " editform are empty, One of these is required"
|
|
||||||
+ " by editRequestDispatch to choose a form.");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
log.debug("Found editform in http parameters.");
|
|
||||||
}
|
|
||||||
request.setAttribute("subjectUri", subjectUri);
|
|
||||||
request.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri));
|
|
||||||
if (predicateUri != null) {
|
|
||||||
request.setAttribute("predicateUri", predicateUri);
|
|
||||||
request.setAttribute("predicateUriJson", MiscWebUtils.escape(predicateUri));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formParam != null && formParam.length() > 0) {
|
|
||||||
request.setAttribute("editForm", formParam);
|
|
||||||
} else {
|
|
||||||
formParam = null;
|
|
||||||
}
|
|
||||||
String objectUri = request.getParameter("objectUri");
|
|
||||||
if (objectUri != null) {
|
|
||||||
request.setAttribute("objectUri", objectUri);
|
|
||||||
request.setAttribute("objectUriJson", MiscWebUtils.escape(objectUri));
|
|
||||||
}
|
|
||||||
if( typeOfNew != null )
|
|
||||||
request.setAttribute("typeOfNew", typeOfNew);
|
|
||||||
|
|
||||||
request.setAttribute("urlPatternToReturnTo", request
|
|
||||||
.getParameter("urlPattern") == null ? "/entity" : request
|
|
||||||
.getParameter("urlPattern"));
|
|
||||||
log.debug("setting urlPatternToReturnTo as "
|
|
||||||
+ request.getAttribute("urlPatternToReturnTo"));
|
|
||||||
|
|
||||||
/* since we have the URIs lets put the individuals in the request */
|
|
||||||
/* get some data to make the form more useful */
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
|
|
||||||
if( subjectUri != null ){
|
|
||||||
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
|
|
||||||
if( subject != null ){
|
|
||||||
request.setAttribute("subject", subject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEditOfExistingStmt = false;
|
|
||||||
if (objectUri != null) {
|
|
||||||
Individual object = wdf.getIndividualDao().getIndividualByURI(
|
|
||||||
objectUri);
|
|
||||||
if (object != null) {
|
|
||||||
request.setAttribute("object", object);
|
|
||||||
isEditOfExistingStmt = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* keep track of what form we are using so it can be returned to after a failed validation */
|
|
||||||
String url = "/edit/editRequestDispatch.jsp"; //I'd like to get this from the request but...
|
|
||||||
request.setAttribute("formUrl", url + "?"
|
|
||||||
+ request.getQueryString());
|
|
||||||
|
|
||||||
request.setAttribute("preForm", "/edit/formPrefix.jsp");
|
|
||||||
request.setAttribute("postForm", "/edit/formSuffix.jsp");
|
|
||||||
|
|
||||||
if ("delete".equals(command)) {
|
|
||||||
%><jsp:forward page="/edit/forms/propDelete.jsp"/><%
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Certain predicates may be annotated to change the behavior of the edit
|
|
||||||
//link. Check for this annnotation and, if present, simply redirect
|
|
||||||
//to the normal individual display for the object URI instead of bringing
|
|
||||||
//up an editing form.
|
|
||||||
//Note that we do not want this behavior for the delete link (handled above).
|
|
||||||
if ( (predicateUri != null) && (objectUri != null) && (wdf.getObjectPropertyDao().skipEditForm(predicateUri)) ) {
|
|
||||||
log.debug("redirecting for predicate " + predicateUri);
|
|
||||||
%><c:redirect url="/individual">
|
|
||||||
<c:param name="uri" value="${param.objectUri}"/>
|
|
||||||
<c:param name="relatedSubjectUri" value="${param.subjectUri}"/>
|
|
||||||
<c:param name="relatingPredicateUri" value="${param.predicateUri}"/>
|
|
||||||
</c:redirect>
|
|
||||||
<%
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (session.getAttribute("requestedFromEntity") == null)
|
|
||||||
session.setAttribute("requestedFromEntity", subjectUri);
|
|
||||||
|
|
||||||
ObjectProperty objectProp = null;
|
|
||||||
String customForm = null;
|
|
||||||
String form = DEFAULT_OBJ_FORM;
|
|
||||||
|
|
||||||
if( predicateUri != null && ( formParam == null || formParam.length() == 0 ) ){
|
|
||||||
objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
|
||||||
customForm = objectProp.getCustomEntryForm();
|
|
||||||
request.setAttribute("predicate", objectProp);
|
|
||||||
//Offer create new and select from existing are ignored if there is a custom form
|
|
||||||
if (customForm != null && customForm.length() > 0) {
|
|
||||||
//bdc34: maybe this should be the custom form on the class, not the property.
|
|
||||||
form = objectProp.getCustomEntryForm();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
boolean isForwardToCreateNew =
|
|
||||||
( objectProp != null && objectProp.getOfferCreateNewOption() && objectProp.getSelectFromExisting() == false)
|
|
||||||
|| ( objectProp != null && objectProp.getOfferCreateNewOption() && "create".equals(command));
|
|
||||||
if (isForwardToCreateNew) {
|
|
||||||
|
|
||||||
request.setAttribute("isForwardToCreateNew", new Boolean(true));
|
|
||||||
|
|
||||||
//If a objectProperty is both provideSelect and offerCreateNewOption
|
|
||||||
// and a user goes to a defaultObjectProperty.jsp form then the user is
|
|
||||||
// offered the option to create a new Individual and replace the
|
|
||||||
// object in the existing objectPropertyStatement with this new individual.
|
|
||||||
boolean isReplaceWithNew =
|
|
||||||
isEditOfExistingStmt && "create".equals(command)
|
|
||||||
&& objectProp != null && objectProp.getOfferCreateNewOption() == true;
|
|
||||||
|
|
||||||
// If an objectProperty is selectFromExisitng==false and offerCreateNewOption == true
|
|
||||||
// the we want to forward to the create new form but edit the existing object
|
|
||||||
// of the objPropStmt.
|
|
||||||
boolean isForwardToCreateButEdit =
|
|
||||||
isEditOfExistingStmt && objectProp != null
|
|
||||||
&& objectProp.getOfferCreateNewOption() == true
|
|
||||||
&& objectProp.getSelectFromExisting() == false
|
|
||||||
&& ! "create".equals(command);
|
|
||||||
|
|
||||||
if( isReplaceWithNew ){
|
|
||||||
request.setAttribute("isReplaceWithNew", new Boolean(true));
|
|
||||||
form = DEFAULT_ADD_INDIVIDUAL;
|
|
||||||
}else if( isForwardToCreateButEdit ){
|
|
||||||
request.setAttribute("isForwardToCreateButEdit", new Boolean(true));
|
|
||||||
form = DEFAULT_ADD_INDIVIDUAL;
|
|
||||||
}else {
|
|
||||||
form = DEFAULT_ADD_INDIVIDUAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ! isForwardToCreateNew ){
|
|
||||||
if( objectProp != null && objectProp.getCustomEntryForm() != null && objectProp.getCustomEntryForm().length() > 0){
|
|
||||||
form = objectProp.getCustomEntryForm();
|
|
||||||
}else{
|
|
||||||
form = DEFAULT_OBJ_FORM ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//case where a form was passed as a http parameter
|
|
||||||
form = formParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If doing old edit, which we must be b/c otherwise we wouldn't be here
|
|
||||||
//then get the other
|
|
||||||
for (Map.Entry<String, String> entry: JspToGeneratorMapping.jspsToGenerators.entrySet()) {
|
|
||||||
if(form.equals(entry.getValue())) {
|
|
||||||
//Get the jsp corresponding to the Java generator
|
|
||||||
form = entry.getKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
request.setAttribute("form", form);
|
|
||||||
%>
|
|
||||||
<jsp:forward page="/edit/forms/${form}" />
|
|
||||||
|
|
||||||
|
|
||||||
<%!
|
|
||||||
|
|
||||||
//bdc34: This isn't used anywhere, don't migrate forward to java code in 1.3
|
|
||||||
private static synchronized void setEditReferer(String editKey, String refererUrl, HttpSession session) {
|
|
||||||
if (refererUrl != null) {
|
|
||||||
Object editRefererObj = session.getAttribute("editRefererMap");
|
|
||||||
HashMap<String,String> editRefererMap =
|
|
||||||
(editRefererObj != null && (editRefererObj instanceof HashMap))
|
|
||||||
? (HashMap<String,String>) editRefererObj
|
|
||||||
: new HashMap<String,String>();
|
|
||||||
session.setAttribute("editRefererMap", editRefererMap);
|
|
||||||
editRefererMap.put(editKey, refererUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%>
|
|
|
@ -1,14 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
|
|
||||||
<jsp:include page="/edit/formPrefix.jsp" >
|
|
||||||
<jsp:param name="useTinyMCE" value="false"/>
|
|
||||||
<jsp:param name="useAutoComplete" value="false"/>
|
|
||||||
</jsp:include>
|
|
||||||
|
|
||||||
<h2>There was a problem uploading your file.</h2>
|
|
||||||
<div>
|
|
||||||
${errors}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<jsp:include page="/edit/formSuffix.jsp" />
|
|
|
@ -1,98 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.*" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
|
||||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
|
||||||
<%@ page errorPage="/error.jsp"%>
|
|
||||||
<%@ page contentType="text/html; charset=UTF-8"%>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet" %>
|
|
||||||
|
|
||||||
<%
|
|
||||||
FreemarkerHttpServlet.getFreemarkerComponentsForJsp(request);
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
|
|
||||||
String contextRoot = vreq.getContextPath();
|
|
||||||
String themeDir = vreq.getAppBean().getThemeDir();
|
|
||||||
|
|
||||||
themeDir = contextRoot + '/' + themeDir;
|
|
||||||
%>
|
|
||||||
|
|
||||||
<c:set var="themeDir"><c:out value="${themeDir}" /></c:set>
|
|
||||||
<c:set var="bodyJsp"><c:out value="${requestScope.bodyJsp}" default="/debug.jsp"/></c:set>
|
|
||||||
<c:set var="title"><c:out value="${requestScope.title}" /></c:set>
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head> <!-- formPrefix.jsp -->
|
|
||||||
<% String useAutoComplete = (useAutoComplete=request.getParameter("useAutoComplete")) != null && !(useAutoComplete.equals("")) ? useAutoComplete : "false";
|
|
||||||
if (useAutoComplete.equalsIgnoreCase("true")) { %>
|
|
||||||
<link rel="stylesheet" type="text/css" href="<c:url value="/js/jquery_plugins/jquery-autocomplete/jquery.autocomplete.css"/>" />
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<c:forEach var="cssFile" items="${customCss}">
|
|
||||||
<link rel="stylesheet" type="text/css" href="<c:url value="${cssFile}"/>" media="screen"/>
|
|
||||||
</c:forEach>
|
|
||||||
|
|
||||||
${ftl_head}
|
|
||||||
|
|
||||||
<c:if test="${!empty scripts}"><jsp:include page="${scripts}"/></c:if>
|
|
||||||
|
|
||||||
<%
|
|
||||||
String useTinyMCE = (useTinyMCE=request.getParameter("useTinyMCE")) != null && !(useTinyMCE.equals("")) ? useTinyMCE : "false";
|
|
||||||
if (useTinyMCE.equalsIgnoreCase("true")) {
|
|
||||||
String height = (height=request.getParameter("height")) != null && !(height.equals("")) ? height : "200";
|
|
||||||
String width = (width=request.getParameter("width")) != null && !(width.equals("")) ? width : "75%";
|
|
||||||
String defaultButtons="bold,italic,underline,separator,link,bullist,numlist,separator,sub,sup,charmap,separator,undo,redo,separator,code";
|
|
||||||
String buttons = (buttons=request.getParameter("buttons")) != null && !(buttons.equals("")) ? buttons : defaultButtons;
|
|
||||||
String tbLocation = (tbLocation=request.getParameter("toolbarLocation")) != null && !(tbLocation.equals("")) ? tbLocation : "top";
|
|
||||||
%>
|
|
||||||
<script language="javascript" type="text/javascript" src="../js/tiny_mce/tiny_mce.js"></script>
|
|
||||||
<script language="javascript" type="text/javascript">
|
|
||||||
tinyMCE.init({
|
|
||||||
theme : "advanced",
|
|
||||||
mode : "textareas",
|
|
||||||
theme_advanced_buttons1 : "<%=buttons%>",
|
|
||||||
theme_advanced_buttons2 : "",
|
|
||||||
theme_advanced_buttons3 : "",
|
|
||||||
theme_advanced_toolbar_location : "<%=tbLocation%>",
|
|
||||||
theme_advanced_toolbar_align : "left",
|
|
||||||
theme_advanced_statusbar_location : "bottom",
|
|
||||||
theme_advanced_path : false,
|
|
||||||
theme_advanced_resizing : true,
|
|
||||||
height : "<%=height%>",
|
|
||||||
width : "<%=width%>",
|
|
||||||
valid_elements : "a[href|name|title],br,p,i,em,cite,strong/b,u,sub,sup,ul,ol,li",
|
|
||||||
fix_list_elements : true,
|
|
||||||
fix_nesting : true,
|
|
||||||
cleanup_on_startup : true,
|
|
||||||
gecko_spellcheck : true,
|
|
||||||
forced_root_block: false
|
|
||||||
//forced_root_block : 'p',
|
|
||||||
// plugins: "paste",
|
|
||||||
// theme_advanced_buttons1_add : "pastetext,pasteword,selectall",
|
|
||||||
// paste_create_paragraphs: false,
|
|
||||||
// paste_create_linebreaks: false,
|
|
||||||
// paste_use_dialog : true,
|
|
||||||
// paste_auto_cleanup_on_paste: true,
|
|
||||||
// paste_convert_headers_to_strong : true
|
|
||||||
// save_callback : "customSave",
|
|
||||||
// content_css : "example_advanced.css",
|
|
||||||
// extended_valid_elements : "a[href|target|name]",
|
|
||||||
// plugins : "table",
|
|
||||||
// theme_advanced_buttons3_add_before : "tablecontrols,separator",
|
|
||||||
// invalid_elements : "li",
|
|
||||||
// theme_advanced_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1", // Theme specific setting CSS classes
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<% } %>
|
|
||||||
</head>
|
|
||||||
<body class="formsEdit">
|
|
||||||
${ftl_identity}
|
|
||||||
|
|
||||||
${ftl_menu}
|
|
||||||
<!-- end of formPrefix.jsp -->
|
|
|
@ -1,46 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.*" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
|
||||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
|
||||||
<%@ page errorPage="/error.jsp"%>
|
|
||||||
<%@ page contentType="text/html; charset=UTF-8"%>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet" %>
|
|
||||||
|
|
||||||
<% /* Prepare Freemarker components to allow .ftl templates to be included from jsp */
|
|
||||||
FreemarkerHttpServlet.getFreemarkerComponentsForJsp(request);
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
|
|
||||||
String contextRoot = vreq.getContextPath();
|
|
||||||
String themeDir = vreq.getAppBean().getThemeDir();
|
|
||||||
|
|
||||||
themeDir = contextRoot + '/' + themeDir;
|
|
||||||
%>
|
|
||||||
|
|
||||||
<c:set var="themeDir"><c:out value="${themeDir}" /></c:set>
|
|
||||||
<c:set var="bodyJsp"><c:out value="${requestScope.bodyJsp}" default="/debug.jsp"/></c:set>
|
|
||||||
<c:set var="title"><c:out value="${requestScope.title}" /></c:set>
|
|
||||||
|
|
||||||
|
|
||||||
${ftl_footer}
|
|
||||||
|
|
||||||
<script type="text/javascript" src="<c:url value="/js/extensions/String.js"/>"></script>
|
|
||||||
<script type="text/javascript" src="<c:url value="/js/jquery_plugins/jquery.bgiframe.pack.js"/>"></script>
|
|
||||||
<!-- <script type="text/javascript" src="<c:url value="/js/jquery_plugins/ui.datepicker.js"/>"></script> -->
|
|
||||||
|
|
||||||
<% String useAutoComplete = (useAutoComplete=request.getParameter("useAutoComplete")) != null && !(useAutoComplete.equals("")) ? useAutoComplete : "false";
|
|
||||||
if (useAutoComplete.equalsIgnoreCase("true")) { %>
|
|
||||||
<script type="text/javascript" src="<c:url value="/js/jquery_plugins/jquery-autocomplete/jquery.autocomplete.pack.js"/>"></script>
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<c:forEach var="jsFile" items="${customJs}">
|
|
||||||
<script type="text/javascript" src="<c:url value="${jsFile}"/>"></script>
|
|
||||||
</c:forEach>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,42 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
|
||||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
|
||||||
<%@ page errorPage="/error.jsp"%>
|
|
||||||
|
|
||||||
<c:set var="errorMsg">
|
|
||||||
The text you are trying to edit cannot be found.
|
|
||||||
</c:set>
|
|
||||||
|
|
||||||
<jsp:include page="/edit/formPrefix.jsp"/>
|
|
||||||
<div id="content" class="full">
|
|
||||||
<div align="center">${errorMsg}</div>
|
|
||||||
|
|
||||||
|
|
||||||
<%
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
if( vreq.getParameter("subjectUri") != null ){
|
|
||||||
Individual individual = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(vreq.getParameter("subjectUri"));
|
|
||||||
String name = "the individual you were trying to edit.";
|
|
||||||
if( individual != null && individual.getName() != null ){
|
|
||||||
name = individual.getName();
|
|
||||||
} %>
|
|
||||||
<c:url value="/entity" var="entityPage">
|
|
||||||
<c:param name="uri"><%=vreq.getParameter("subjectUri")%></c:param>
|
|
||||||
</c:url>
|
|
||||||
<div align="center">
|
|
||||||
<button type="button"
|
|
||||||
onclick="javascript:document.location.href='${entityPage}'">
|
|
||||||
Return to <%=name%></button>
|
|
||||||
</div>
|
|
||||||
<%}else{ %>
|
|
||||||
<c:url value="/" var="siteRoot"/>
|
|
||||||
<div align="center">
|
|
||||||
<button type="button"
|
|
||||||
onclick="javascript:document.location.href='${siteRoot}'">
|
|
||||||
Return to main site</button>
|
|
||||||
</div>
|
|
||||||
<%} %>
|
|
||||||
|
|
||||||
<jsp:include page="/edit/formSuffix.jsp"/>
|
|
|
@ -1,262 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.*" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.ontology.OntModel" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.shared.Lock" %>
|
|
||||||
<%@ page import="com.thoughtworks.xstream.XStream" %>
|
|
||||||
<%@ page import="com.thoughtworks.xstream.io.xml.DomDriver" %>
|
|
||||||
<%@ 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.EditLiteral" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.Log" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
|
||||||
<%@ page import="java.io.StringReader" %>
|
|
||||||
<%@ page import="java.util.*" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty"%>
|
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
|
||||||
|
|
||||||
<%--
|
|
||||||
Current stop gap solution for back button problems
|
|
||||||
the data property statement to replace cannot be found:
|
|
||||||
|
|
||||||
Just add the new data property statement, do not remove any statements
|
|
||||||
and set a flag in the request to indicate "back button confusion"
|
|
||||||
|
|
||||||
|
|
||||||
--%>
|
|
||||||
<%!
|
|
||||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.datapropertyBackButtonProblems.jsp");
|
|
||||||
%>
|
|
||||||
<%
|
|
||||||
log.debug("Starting datapropertyBackButtonProblems.jsp");
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousPages" %>
|
|
||||||
<% request.setAttribute("requestedActions", new UseMiscellaneousPages()); %>
|
|
||||||
<vitro:confirmAuthorization />
|
|
||||||
|
|
||||||
<%
|
|
||||||
List<String> errorMessages = new ArrayList<String>();
|
|
||||||
Object sessionOntModel = request.getSession().getAttribute("jenaOntModel");
|
|
||||||
OntModel jenaOntModel = (sessionOntModel != null && sessionOntModel instanceof OntModel) ? (OntModel)sessionOntModel:
|
|
||||||
(OntModel)application.getAttribute("jenaOntModel");
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq);
|
|
||||||
EditSubmission submission = new EditSubmission(vreq.getParameterMap(), editConfig);
|
|
||||||
|
|
||||||
EditN3Generator n3Subber = editConfig.getN3Generator();
|
|
||||||
List<String> n3Required = editConfig.getN3Required();
|
|
||||||
|
|
||||||
Map<String,List<String>> fieldAssertions = null;
|
|
||||||
String subjectUri=null, predicateUri=null;
|
|
||||||
Individual subject=null;
|
|
||||||
if( editConfig.getDatapropKey() != null && editConfig.getDatapropKey().length() > 0){
|
|
||||||
// we are editing an existing data property statement
|
|
||||||
subjectUri = editConfig.getSubjectUri();
|
|
||||||
if (subjectUri == null || subjectUri.trim().length()==0) {
|
|
||||||
log.error("No subjectUri parameter available via editConfig for datapropKey "+editConfig.getDatapropKey());
|
|
||||||
throw new Error("No subjectUri parameter available via editConfig in processDatapropRdfForm.jsp");
|
|
||||||
}
|
|
||||||
predicateUri = editConfig.getPredicateUri();
|
|
||||||
if (predicateUri == null || predicateUri.trim().length()==0) {
|
|
||||||
log.error("No predicateUri parameter available via editConfig for datapropKey "+editConfig.getDatapropKey());
|
|
||||||
throw new Error("No predicateUri parameter available via editConfig in processDatapropRdfForm.jsp");
|
|
||||||
}
|
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
|
|
||||||
// need to get subject because have to iterate through all its data property statements to match datapropKey hashcode
|
|
||||||
subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
|
|
||||||
if( subject == null ) {
|
|
||||||
log.error("Could not find subject Individual via editConfig's subjectUri while proceessing update to datapropKey "+editConfig.getDatapropKey());
|
|
||||||
throw new Error("In processDatapropRdfForm.jsp, could not find subject Individual via uri " + subjectUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldAssertions = fieldsToMap(editConfig.getFields());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
|
||||||
//sub in resource uris off form
|
|
||||||
n3Required = n3Subber.subInUris(submission.getUrisFromForm(), n3Required);
|
|
||||||
|
|
||||||
//sub in literals from form
|
|
||||||
n3Required = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Required);
|
|
||||||
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions );
|
|
||||||
|
|
||||||
/* ****************** URIs and Literals in Scope ************** */
|
|
||||||
n3Required = n3Subber.subInUris( editConfig.getUrisInScope(), n3Required);
|
|
||||||
|
|
||||||
n3Required = n3Subber.subInLiterals( editConfig.getLiteralsInScope(), n3Required);
|
|
||||||
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(editConfig.getUrisInScope(),editConfig.getLiteralsInScope(), fieldAssertions );
|
|
||||||
|
|
||||||
/* ****************** New Resources ********************** */
|
|
||||||
Map<String,String> varToNewResource = newToUriMap(editConfig.getNewResources(),jenaOntModel);
|
|
||||||
|
|
||||||
//if we are editing an existing prop, no new resources will be substituted since the var will
|
|
||||||
//have already been substituted in by urisInScope.
|
|
||||||
n3Required = n3Subber.subInUris( varToNewResource, n3Required);
|
|
||||||
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(varToNewResource, null, fieldAssertions );
|
|
||||||
|
|
||||||
/* ***************** Build Models ******************* */
|
|
||||||
/* bdc34: we should check if this is an edit of an existing
|
|
||||||
or a new individual. If this is a edit of an existing then
|
|
||||||
we don't need to do the n3required or the n3optional; only the
|
|
||||||
the assertions and retractions from the fields are needed.
|
|
||||||
*/
|
|
||||||
List<Model> requiredAssertions = null;
|
|
||||||
List<Model> requiredRetractions = null;
|
|
||||||
|
|
||||||
if( editConfig.getDatapropKey() != null && editConfig.getDatapropKey().trim().length() > 0 ){
|
|
||||||
//editing an existing statement
|
|
||||||
List<Model> requiredFieldAssertions = new ArrayList<Model>();
|
|
||||||
List<Model> requiredFieldRetractions = new ArrayList<Model>();
|
|
||||||
for(String fieldName: fieldAssertions.keySet()){
|
|
||||||
Field field = editConfig.getFields().get(fieldName);
|
|
||||||
/* CHECK that field changed, then add assertions and retractions */
|
|
||||||
if( hasFieldChanged(fieldName, editConfig, submission) ){
|
|
||||||
log.debug("Field "+fieldName+" has changed for datapropKey "+editConfig.getDatapropKey());
|
|
||||||
List<String> assertions = fieldAssertions.get(fieldName);
|
|
||||||
for( String n3 : assertions){
|
|
||||||
try{
|
|
||||||
log.debug("Adding assertion '"+n3+"' to requiredFieldAssertions");
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredFieldAssertions.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
log.warn("processing N3 assertions string from field "+fieldName+"\n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
errorMessages.add("error processing N3 assertion string from field " + fieldName + "\n"+
|
|
||||||
t.getMessage() + '\n' +
|
|
||||||
"n3: \n" + n3 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (field.getRetractions()!=null) {
|
|
||||||
for( String n3 : field.getRetractions()){
|
|
||||||
try{
|
|
||||||
log.debug("Adding retraction '"+n3+"' to requiredFieldRetractions");
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredFieldRetractions.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
log.warn("processing N3 retraction string from field "+fieldName+"\n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
errorMessages.add("error in processDatapropRdfForm.jsp processing N3 retraction string from field "+fieldName+"\n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requiredAssertions = requiredFieldAssertions;
|
|
||||||
requiredRetractions = requiredFieldRetractions;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Lock lock = null;
|
|
||||||
try{
|
|
||||||
lock = jenaOntModel.getLock();
|
|
||||||
lock.enterCriticalSection(Lock.WRITE);
|
|
||||||
for( Model model : requiredAssertions) {
|
|
||||||
jenaOntModel.add(model);
|
|
||||||
}
|
|
||||||
for(Model model : requiredRetractions ){
|
|
||||||
jenaOntModel.remove( model );
|
|
||||||
}
|
|
||||||
}catch(Throwable t){
|
|
||||||
errorMessages.add("In datapropertyBackButtonProblems.jsp, error adding edit change n3required model to in memory model \n"+ t.getMessage() );
|
|
||||||
}finally{
|
|
||||||
lock.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
|
|
||||||
<jsp:forward page="../postEditCleanUp.jsp"/>
|
|
||||||
|
|
||||||
<%!
|
|
||||||
|
|
||||||
/* ********************************************************* */
|
|
||||||
/* ******************** utility functions ****************** */
|
|
||||||
/* ********************************************************* */
|
|
||||||
|
|
||||||
public Map<String,List<String>> fieldsToMap( Map<String,Field> fields){
|
|
||||||
Map<String,List<String>> out = new HashMap<String,List<String>>();
|
|
||||||
for( String fieldName : fields.keySet()){
|
|
||||||
Field field = fields.get(fieldName);
|
|
||||||
|
|
||||||
List<String> copyOfN3 = new ArrayList<String>();
|
|
||||||
for( String str : field.getAssertions()){
|
|
||||||
copyOfN3.add(str);
|
|
||||||
}
|
|
||||||
out.put( fieldName, copyOfN3 );
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String,String> newToUriMap(Map<String,String> newResources, Model model){
|
|
||||||
HashMap<String,String> newUris = new HashMap<String,String>();
|
|
||||||
for( String key : newResources.keySet()){
|
|
||||||
newUris.put(key,makeNewUri(newResources.get(key), model));
|
|
||||||
}
|
|
||||||
return newUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String makeNewUri(String prefix, Model model){
|
|
||||||
if( prefix == null || prefix.length() == 0 )
|
|
||||||
prefix = defaultUriPrefix;
|
|
||||||
|
|
||||||
String uri = prefix + random.nextInt();
|
|
||||||
Resource r = ResourceFactory.createResource(uri);
|
|
||||||
while( model.containsResource(r) ){
|
|
||||||
uri = prefix + random.nextInt();
|
|
||||||
r = ResourceFactory.createResource(uri);
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Random random = new Random();
|
|
||||||
static String defaultUriPrefix = "http://vivo.library.cornell.edu/ns/0.1#individual";
|
|
||||||
%>
|
|
||||||
|
|
||||||
|
|
||||||
<%!
|
|
||||||
private boolean hasFieldChanged(String fieldName, EditConfiguration editConfig, EditSubmission submission) {
|
|
||||||
String orgValue = editConfig.getUrisInScope().get(fieldName);
|
|
||||||
String newValue = submission.getUrisFromForm().get(fieldName);
|
|
||||||
if( orgValue != null && newValue != null){
|
|
||||||
if( orgValue.equals(newValue))
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Literal orgLit = editConfig.getLiteralsInScope().get(fieldName);
|
|
||||||
Literal newLit = submission.getLiteralsFromForm().get(fieldName);
|
|
||||||
boolean fieldChanged = !EditLiteral.equalLiterals( orgLit, newLit);
|
|
||||||
log.debug( "field " + fieldName + " " + (fieldChanged ? "did Change" : "did NOT change") );
|
|
||||||
return fieldChanged;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dump(String name, Object fff){
|
|
||||||
XStream xstream = new XStream(new DomDriver());
|
|
||||||
Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.processDatapropRdfForm.jsp");
|
|
||||||
log.debug( "*******************************************************************" );
|
|
||||||
log.debug( name );
|
|
||||||
log.debug(xstream.toXML( fff ));
|
|
||||||
}
|
|
||||||
%>
|
|
|
@ -1,42 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
|
||||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
|
||||||
<%@ page errorPage="/error.jsp"%>
|
|
||||||
|
|
||||||
<c:set var="errorMsg">
|
|
||||||
We are not sure what you would like to edit.
|
|
||||||
</c:set>
|
|
||||||
|
|
||||||
<jsp:include page="/edit/formPrefix.jsp"/>
|
|
||||||
<div id="content" class="full">
|
|
||||||
<div align="center">${errorMsg}</div>
|
|
||||||
|
|
||||||
|
|
||||||
<%
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
if( vreq.getParameter("subjectUri") != null ){
|
|
||||||
Individual individual = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(vreq.getParameter("subjectUri"));
|
|
||||||
String name = "the individual you were trying to edit.";
|
|
||||||
if( individual != null && individual.getName() != null ){ %>
|
|
||||||
name = individual.getName() + ".";
|
|
||||||
<% } %>
|
|
||||||
<c:url value="/entity" var="entityPage">
|
|
||||||
<c:param name="uri"><%=vreq.getParameter("subjectUri")%></c:param>
|
|
||||||
</c:url>
|
|
||||||
<div align="center">
|
|
||||||
<button type="button"
|
|
||||||
onclick="javascript:document.location.href='${entityPage}'">
|
|
||||||
Return to <%=name%></button>
|
|
||||||
</div>
|
|
||||||
<%}else{ %>
|
|
||||||
<c:url value="/" var="siteRoot"/>
|
|
||||||
<div align="center">
|
|
||||||
<button type="button"
|
|
||||||
onclick="javascript:document.location.href='${siteRoot}'">
|
|
||||||
Return to main site</button>
|
|
||||||
</div>
|
|
||||||
<%} %>
|
|
||||||
|
|
||||||
<jsp:include page="/edit/formSuffix.jsp"/>
|
|
|
@ -1,95 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
|
||||||
<%@ page import="org.apache.commons.lang.StringUtils" %>
|
|
||||||
<%@page import="org.apache.commons.logging.Log"%>
|
|
||||||
<%@page import="org.apache.commons.logging.LogFactory"%>
|
|
||||||
<%@page import="com.hp.hpl.jena.rdf.model.ResourceFactory"%>
|
|
||||||
<%@page import="com.hp.hpl.jena.rdf.model.Property"%>
|
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
|
||||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jstl/functions" %>
|
|
||||||
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.1" prefix="str" %>
|
|
||||||
|
|
||||||
|
|
||||||
<%
|
|
||||||
/* Clear any cruft from session. */
|
|
||||||
String resourceToRedirectTo = null;
|
|
||||||
String urlPattern = null;
|
|
||||||
String predicateLocalName = null;
|
|
||||||
String predicateAnchor = "";
|
|
||||||
if( session != null ) {
|
|
||||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
|
|
||||||
//In order to support back button resubmissions, don't remove the editConfig from session.
|
|
||||||
//EditConfiguration.clearEditConfigurationInSession(session, editConfig);
|
|
||||||
|
|
||||||
EditSubmission editSub = EditSubmission.getEditSubmissionFromSession(session,editConfig);
|
|
||||||
EditSubmission.clearEditSubmissionInSession(session, editSub);
|
|
||||||
|
|
||||||
if( editConfig != null ){
|
|
||||||
String predicateUri = editConfig.getPredicateUri();
|
|
||||||
if( predicateUri != null ){
|
|
||||||
try{
|
|
||||||
Property prop = ResourceFactory.createProperty(predicateUri);
|
|
||||||
predicateLocalName = prop.getLocalName();
|
|
||||||
}catch (com.hp.hpl.jena.shared.InvalidPropertyURIException e){
|
|
||||||
log.debug("could not convert predicateUri into a valid URI",e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( editConfig.getEntityToReturnTo() != null && editConfig.getEntityToReturnTo().startsWith("?") ){
|
|
||||||
resourceToRedirectTo = (String)request.getAttribute("entityToReturnTo");
|
|
||||||
}else{
|
|
||||||
resourceToRedirectTo = editConfig.getEntityToReturnTo();
|
|
||||||
}
|
|
||||||
|
|
||||||
//if there is no entity to return to it is likely a cancel
|
|
||||||
if( resourceToRedirectTo == null || resourceToRedirectTo.length() == 0 )
|
|
||||||
resourceToRedirectTo = editConfig.getSubjectUri();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//set up base URL
|
|
||||||
String cancel = request.getParameter("cancel");
|
|
||||||
String urlPatternToReturnTo = null;
|
|
||||||
String urlPatternToCancelTo = null;
|
|
||||||
if (editConfig != null) {
|
|
||||||
urlPatternToReturnTo = editConfig.getUrlPatternToReturnTo();
|
|
||||||
urlPatternToCancelTo = request.getParameter("url");
|
|
||||||
}
|
|
||||||
// If a different cancel return path has been designated, use it. Otherwise, use the regular return path.
|
|
||||||
if ("true".equals(cancel) && !StringUtils.isEmpty(urlPatternToCancelTo)) {
|
|
||||||
urlPattern = urlPatternToCancelTo;
|
|
||||||
}
|
|
||||||
else if (!StringUtils.isEmpty(urlPatternToReturnTo)) {
|
|
||||||
urlPattern = urlPatternToReturnTo;
|
|
||||||
} else {
|
|
||||||
urlPattern = "/individual";
|
|
||||||
}
|
|
||||||
|
|
||||||
//looks like a redirect to a profile page, try to add anchor for property that was just edited.
|
|
||||||
if( urlPattern.endsWith("individual") || urlPattern.endsWith("entity") ){
|
|
||||||
if( predicateLocalName != null && predicateLocalName.length() > 0){
|
|
||||||
predicateAnchor = "#" + predicateLocalName;
|
|
||||||
request.setAttribute("predicateAnchor", predicateAnchor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( resourceToRedirectTo != null ){ %>
|
|
||||||
<c:url context="/" var="encodedUrl" value="<%=urlPattern%>">
|
|
||||||
<c:param name="uri" value="<%=resourceToRedirectTo%>" />
|
|
||||||
<c:param name="extra" value="true"/> <%-- For ie6 --%>
|
|
||||||
</c:url>
|
|
||||||
<c:redirect url="${encodedUrl}${predicateAnchor}" />
|
|
||||||
<% } else { %>
|
|
||||||
<c:redirect url="<%= Controllers.LOGIN %>" />
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<%!
|
|
||||||
Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.edit.postEditCleanUp.jsp");
|
|
||||||
%>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,421 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.*" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.ontology.OntModel" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.shared.Lock" %>
|
|
||||||
<%@ page import="com.thoughtworks.xstream.XStream" %>
|
|
||||||
<%@ page import="com.thoughtworks.xstream.io.xml.DomDriver" %>
|
|
||||||
<%@ 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.EditLiteral" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.Log" %>
|
|
||||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
|
||||||
<%@ page import="java.io.StringReader" %>
|
|
||||||
<%@ page import="java.util.*" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%>
|
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
|
||||||
|
|
||||||
<%-- 2nd prototype of processing, adapted for data property editing
|
|
||||||
|
|
||||||
This one takes one list of n3 for a single data property statement field,
|
|
||||||
and there will be no optional fields. If the variables in the required n3
|
|
||||||
are not bound or it cannot be processed as n3 by Jena then it is an error
|
|
||||||
in processing the form.
|
|
||||||
|
|
||||||
Handling back button submissions:
|
|
||||||
As of 2008-08 this code can handle a single back button submission. Deeper
|
|
||||||
back button submissions are handled by just creating the requested property
|
|
||||||
with the requested literal value and setting a request attribute to indicate
|
|
||||||
"back button confusion" It is painful to the user to just give them an error
|
|
||||||
page since they might have just spent 5 min. typing in a value.
|
|
||||||
|
|
||||||
When an data property edit submission is POSTed it includes the subjectURI,
|
|
||||||
the predicateURI, the new Literal and a hash of the Literal to be replaced.
|
|
||||||
When a client POSTs a form that they received after several other POSTs
|
|
||||||
involving the same data property and Literal, there is a chance that the
|
|
||||||
data property statement to be replaced, with the Literal identified by the hash
|
|
||||||
in the POST, is no longer in the model.
|
|
||||||
|
|
||||||
Current stop gap solution:
|
|
||||||
If we cannot find the data property statement to replace:
|
|
||||||
If the data property is functional then just delete the single existing statement
|
|
||||||
and replace with he new one.
|
|
||||||
Otherwise, just add the new data property statement, don't remove any statements
|
|
||||||
and set a flag in the request to indicate "back button confusion"
|
|
||||||
|
|
||||||
--%>
|
|
||||||
<%!
|
|
||||||
final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.processDatapropRdfForm.jsp");
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousPages" %>
|
|
||||||
<% request.setAttribute("requestedActions", new UseMiscellaneousPages()); %>
|
|
||||||
<vitro:confirmAuthorization />
|
|
||||||
|
|
||||||
<%
|
|
||||||
log.debug("Starting processDatapropRdfForm.jsp");
|
|
||||||
|
|
||||||
List<String> errorMessages = new ArrayList<String>();
|
|
||||||
|
|
||||||
//Object sessionOntModel = request.getSession().getAttribute("jenaOntModel");
|
|
||||||
//OntModel jenaOntModel = (sessionOntModel != null && sessionOntModel instanceof OntModel) ? (OntModel)sessionOntModel:
|
|
||||||
// (OntModel)application.getAttribute("jenaOntModel");
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq);
|
|
||||||
if( editConfig == null ){
|
|
||||||
%><jsp:forward page="/edit/messages/noEditConfigFound.jsp"/><%
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditSubmission submission = new EditSubmission(vreq.getParameterMap(), editConfig);
|
|
||||||
|
|
||||||
Map<String,String> errors = submission.getValidationErrors();
|
|
||||||
EditSubmission.putEditSubmissionInSession(session,submission);
|
|
||||||
|
|
||||||
if( errors != null && ! errors.isEmpty() ){
|
|
||||||
String form = editConfig.getFormUrl();
|
|
||||||
vreq.setAttribute("formUrl", form);
|
|
||||||
%><jsp:forward page="${formUrl}"/><%
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OntModel queryModel = editConfig.getQueryModelSelector().getModel(request,application);
|
|
||||||
OntModel resourcesModel = editConfig.getResourceModelSelector().getModel(request,application);
|
|
||||||
|
|
||||||
EditN3Generator n3Subber = editConfig.getN3Generator();
|
|
||||||
List<String> n3Required = editConfig.getN3Required();
|
|
||||||
|
|
||||||
Map<String,List<String>> fieldAssertions = null;
|
|
||||||
String subjectUri=null, predicateUri=null;
|
|
||||||
Individual subject=null;
|
|
||||||
if( editConfig.getDatapropKey() != null && editConfig.getDatapropKey().length() > 0){
|
|
||||||
// we are editing an existing data property statement
|
|
||||||
subjectUri = editConfig.getSubjectUri();
|
|
||||||
if (subjectUri == null || subjectUri.trim().length()==0) {
|
|
||||||
log.error("No subjectUri parameter available via editConfig for datapropKey "+editConfig.getDatapropKey());
|
|
||||||
throw new Error("No subjectUri parameter available via editConfig in processDatapropRdfForm.jsp");
|
|
||||||
}
|
|
||||||
predicateUri = editConfig.getPredicateUri();
|
|
||||||
if (predicateUri == null || predicateUri.trim().length()==0) {
|
|
||||||
log.error("No predicateUri parameter available via editConfig for datapropKey "+editConfig.getDatapropKey());
|
|
||||||
throw new Error("No predicateUri parameter available via editConfig in processDatapropRdfForm.jsp");
|
|
||||||
}
|
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
|
|
||||||
// need to get subject because have to iterate through all its data property statements to match datapropKey hashcode
|
|
||||||
subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
|
|
||||||
if( subject == null ) {
|
|
||||||
log.error("Could not find subject Individual via editConfig's subjectUri while proceessing update to datapropKey "+editConfig.getDatapropKey());
|
|
||||||
throw new Error("In processDatapropRdfForm.jsp, could not find subject Individual via uri " + subjectUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean backButtonProblems = checkForBackButtonConfusion(vreq, application, submission, editConfig, subject, wdf);
|
|
||||||
if( backButtonProblems ){
|
|
||||||
%><jsp:forward page="/edit/messages/datapropertyBackButtonProblems.jsp"/><%
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldAssertions = fieldsToMap(editConfig.getFields());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
|
||||||
//sub in resource uris off form
|
|
||||||
n3Required = n3Subber.subInUris(submission.getUrisFromForm(), n3Required);
|
|
||||||
|
|
||||||
//sub in literals from form
|
|
||||||
n3Required = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Required);
|
|
||||||
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions );
|
|
||||||
|
|
||||||
/* ****************** URIs and Literals in Scope ************** */
|
|
||||||
n3Required = n3Subber.subInUris( editConfig.getUrisInScope(), n3Required);
|
|
||||||
|
|
||||||
n3Required = n3Subber.subInLiterals( editConfig.getLiteralsInScope(), n3Required);
|
|
||||||
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(editConfig.getUrisInScope(),editConfig.getLiteralsInScope(), fieldAssertions );
|
|
||||||
|
|
||||||
/* ****************** New Resources ********************** */
|
|
||||||
Map<String,String> varToNewResource = newToUriMap(editConfig.getNewResources(),resourcesModel);
|
|
||||||
|
|
||||||
//if we are editing an existing prop, no new resources will be substituted since the var will
|
|
||||||
//have already been substituted in by urisInScope.
|
|
||||||
n3Required = n3Subber.subInUris( varToNewResource, n3Required);
|
|
||||||
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(varToNewResource, null, fieldAssertions );
|
|
||||||
|
|
||||||
/* ***************** Build Models ******************* */
|
|
||||||
/* bdc34: we should check if this is an edit of an existing
|
|
||||||
or a new individual. If this is a edit of an existing then
|
|
||||||
we don't need to do the n3required or the n3optional; only the
|
|
||||||
the assertions and retractions from the fields are needed.
|
|
||||||
*/
|
|
||||||
List<Model> requiredAssertions = null;
|
|
||||||
List<Model> requiredRetractions = null;
|
|
||||||
|
|
||||||
boolean submissionWasAnUpdate = false;
|
|
||||||
if( editConfig.getDatapropKey() != null && editConfig.getDatapropKey().trim().length() > 0 ){
|
|
||||||
//editing an existing statement
|
|
||||||
submissionWasAnUpdate = true;
|
|
||||||
|
|
||||||
List<Model> requiredFieldAssertions = new ArrayList<Model>();
|
|
||||||
List<Model> requiredFieldRetractions = new ArrayList<Model>();
|
|
||||||
for(String fieldName: fieldAssertions.keySet()){
|
|
||||||
Field field = editConfig.getFields().get(fieldName);
|
|
||||||
/* CHECK that field changed, then add assertions and retractions */
|
|
||||||
if( hasFieldChanged(fieldName, editConfig, submission) ){
|
|
||||||
log.debug("Field "+fieldName+" has changed for datapropKey "+editConfig.getDatapropKey());
|
|
||||||
|
|
||||||
List<String> assertions = fieldAssertions.get(fieldName);
|
|
||||||
for( String n3 : assertions){
|
|
||||||
try{
|
|
||||||
log.debug("Adding assertion '"+n3+"' to requiredFieldAssertions");
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredFieldAssertions.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
log.warn("processing N3 assertions string from field "+fieldName+"\n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
errorMessages.add("error processing N3 assertion string from field " + fieldName + "\n"+
|
|
||||||
t.getMessage() + '\n' +
|
|
||||||
"n3: \n" + n3 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (field.getRetractions()!=null) {
|
|
||||||
for( String n3 : field.getRetractions()){
|
|
||||||
try{
|
|
||||||
log.debug("Adding retraction '"+n3+"' to requiredFieldRetractions");
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredFieldRetractions.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
log.warn("processing N3 retraction string from field "+fieldName+"\n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
errorMessages.add("error in processDatapropRdfForm.jsp processing N3 retraction string from field "+fieldName+"\n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(checkForEmptyString(submission, editConfig)){
|
|
||||||
//don't assert the empty string dataproperty
|
|
||||||
requiredFieldAssertions.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requiredAssertions = requiredFieldAssertions;
|
|
||||||
requiredRetractions = requiredFieldRetractions;
|
|
||||||
|
|
||||||
} else { //deal with required N3
|
|
||||||
submissionWasAnUpdate = false;
|
|
||||||
log.debug("Not editing an existing statement since no datapropKey in editConfig");
|
|
||||||
|
|
||||||
List<Model> requiredNewModels = new ArrayList<Model>();
|
|
||||||
for(String n3 : n3Required){
|
|
||||||
try{
|
|
||||||
log.debug("Adding assertion '"+n3+"' to requiredNewModels");
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredNewModels.add( model );
|
|
||||||
}catch(Throwable t){
|
|
||||||
log.warn("error processing required n3 string \n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
errorMessages.add("error processing required n3 string \n"+t.getMessage()+'\n'+"n3: \n"+n3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
requiredRetractions = Collections.EMPTY_LIST;
|
|
||||||
if( !checkForEmptyString(submission, editConfig) ){
|
|
||||||
requiredAssertions = requiredNewModels;
|
|
||||||
|
|
||||||
if( !errorMessages.isEmpty() ){
|
|
||||||
for( String error : errorMessages){
|
|
||||||
log.debug(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
//doing an empty field delete, see Issue VITRO-432
|
|
||||||
requiredAssertions = Collections.EMPTY_LIST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OntModel writeModel = editConfig.getWriteModelSelector().getModel(request,application);
|
|
||||||
Lock lock = null;
|
|
||||||
String editorUri = EditN3Utils.getEditorUri(request);
|
|
||||||
try{
|
|
||||||
lock = writeModel.getLock();
|
|
||||||
lock.enterCriticalSection(Lock.WRITE);
|
|
||||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,true));
|
|
||||||
for( Model model : requiredAssertions) {
|
|
||||||
writeModel.add(model);
|
|
||||||
}
|
|
||||||
for(Model model : requiredRetractions ){
|
|
||||||
writeModel.remove( model );
|
|
||||||
}
|
|
||||||
}catch(Throwable t){
|
|
||||||
errorMessages.add("In processDatapropRdfForm.jsp, error adding edit change n3required model to in memory model \n"+ t.getMessage() );
|
|
||||||
}finally{
|
|
||||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,false));
|
|
||||||
lock.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//now setup an EditConfiguration so a single back button submissions can be handled
|
|
||||||
EditConfiguration copy = editConfig.copy();
|
|
||||||
|
|
||||||
//need a new DataPropHash and a new editConfig that uses that, and replace
|
|
||||||
//the editConfig used for this submission in the session. The same thing
|
|
||||||
//is done for an update or a new insert since it will convert the insert
|
|
||||||
//EditConfig into an update EditConfig.
|
|
||||||
log.debug("attempting to make an updated copy of the editConfig for browser back button support");
|
|
||||||
Field dataField = copy.getField(copy.getVarNameForObject());
|
|
||||||
|
|
||||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
|
||||||
Literal submitted = submission.getLiteralsFromForm().get(copy.getVarNameForObject());
|
|
||||||
if( submitted != null ){
|
|
||||||
dps.setIndividualURI( copy.getSubjectUri() );
|
|
||||||
dps.setDatapropURI( copy.getPredicateUri() );
|
|
||||||
dps.setDatatypeURI( submitted.getDatatypeURI());
|
|
||||||
dps.setLanguage( submitted.getLanguage() );
|
|
||||||
dps.setData( submitted.getLexicalForm() );
|
|
||||||
|
|
||||||
copy.prepareForDataPropUpdate(writeModel, dps);
|
|
||||||
copy.setDatapropKey( Integer.toString(RdfLiteralHash.makeRdfLiteralHash(dps)) );
|
|
||||||
EditConfiguration.putConfigInSession(copy,session);
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
|
|
||||||
<jsp:forward page="postEditCleanUp.jsp"/>
|
|
||||||
|
|
||||||
<%!/* ********************************************************* */
|
|
||||||
/* ******************** utility functions ****************** */
|
|
||||||
/* ********************************************************* */
|
|
||||||
|
|
||||||
public Map<String, List<String>> fieldsToMap(Map<String, Field> fields) {
|
|
||||||
Map<String, List<String>> out = new HashMap<String, List<String>>();
|
|
||||||
for (String fieldName : fields.keySet()) {
|
|
||||||
Field field = fields.get(fieldName);
|
|
||||||
|
|
||||||
List<String> copyOfN3 = new ArrayList<String>();
|
|
||||||
for (String str : field.getAssertions()) {
|
|
||||||
copyOfN3.add(str);
|
|
||||||
}
|
|
||||||
out.put(fieldName, copyOfN3);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> newToUriMap(Map<String, String> newResources,
|
|
||||||
Model model) {
|
|
||||||
HashMap<String, String> newUris = new HashMap<String, String>();
|
|
||||||
for (String key : newResources.keySet()) {
|
|
||||||
newUris.put(key, makeNewUri(newResources.get(key), model));
|
|
||||||
}
|
|
||||||
return newUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String makeNewUri(String prefix, Model model) {
|
|
||||||
if (prefix == null || prefix.length() == 0)
|
|
||||||
prefix = defaultUriPrefix;
|
|
||||||
|
|
||||||
String uri = prefix + random.nextInt();
|
|
||||||
Resource r = ResourceFactory.createResource(uri);
|
|
||||||
while (model.containsResource(r)) {
|
|
||||||
uri = prefix + random.nextInt();
|
|
||||||
r = ResourceFactory.createResource(uri);
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Random random = new Random();
|
|
||||||
|
|
||||||
static String defaultUriPrefix = "http://vivo.library.cornell.edu/ns/0.1#individual";%>
|
|
||||||
|
|
||||||
|
|
||||||
<%!private boolean hasFieldChanged(String fieldName,
|
|
||||||
EditConfiguration editConfig, EditSubmission submission) {
|
|
||||||
String orgValue = editConfig.getUrisInScope().get(fieldName);
|
|
||||||
String newValue = submission.getUrisFromForm().get(fieldName);
|
|
||||||
if (orgValue != null && newValue != null) {
|
|
||||||
if (orgValue.equals(newValue))
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Literal orgLit = editConfig.getLiteralsInScope().get(fieldName);
|
|
||||||
Literal newLit = submission.getLiteralsFromForm().get(fieldName);
|
|
||||||
boolean fieldChanged = !EditLiteral.equalLiterals(orgLit, newLit);
|
|
||||||
log.debug("field " + fieldName + " "
|
|
||||||
+ (fieldChanged ? "did Change" : "did NOT change"));
|
|
||||||
return fieldChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkForBackButtonConfusion(VitroRequest vreq, ServletContext application, EditSubmission submission,
|
|
||||||
EditConfiguration editConfig, Individual subject,
|
|
||||||
WebappDaoFactory wdf) {
|
|
||||||
if (editConfig.getDatapropKey() == null
|
|
||||||
|| editConfig.getDatapropKey().length() == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
|
||||||
int dpropHash = Integer.parseInt(editConfig.getDatapropKey());
|
|
||||||
DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject.getURI(), editConfig.getPredicateUri(), dpropHash, model);
|
|
||||||
|
|
||||||
if (dps != null)
|
|
||||||
return false;
|
|
||||||
DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI(
|
|
||||||
editConfig.getPredicateUri());
|
|
||||||
if (dp != null) {
|
|
||||||
if (dp.getDisplayLimit() == 1 /* || dp.isFunctional() */)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Our editors have gotten into the habbit of clearing the text from the
|
|
||||||
// textarea and saving it to invoke a delete. see Issue VITRO-432
|
|
||||||
private boolean checkForEmptyString(EditSubmission submission,
|
|
||||||
EditConfiguration editConfig) {
|
|
||||||
if (editConfig.getFields().size() == 1) {
|
|
||||||
String onlyField = editConfig.getFields().keySet().iterator()
|
|
||||||
.next();
|
|
||||||
Literal value = submission.getLiteralsFromForm().get(onlyField);
|
|
||||||
if( value == null ){
|
|
||||||
log.debug("No parameters found in submission for field \"" + onlyField +"\"");
|
|
||||||
return true;
|
|
||||||
}else if( "".equals(value.getLexicalForm())) {
|
|
||||||
log.debug("Submission was a single field named \"" + onlyField + "\" with an empty string");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void dump(String name, Object fff) {
|
|
||||||
XStream xstream = new XStream(new DomDriver());
|
|
||||||
Log log = LogFactory
|
|
||||||
.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.processDatapropRdfForm.jsp");
|
|
||||||
log
|
|
||||||
.debug("*******************************************************************");
|
|
||||||
log.debug(name);
|
|
||||||
log.debug(xstream.toXML(fff));
|
|
||||||
}%>
|
|
|
@ -1,522 +0,0 @@
|
||||||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
|
||||||
|
|
||||||
<%@ page import="com.hp.hpl.jena.ontology.OntModel" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.ModelFactory" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.Resource" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.ResourceFactory" %>
|
|
||||||
<%@ page import="com.hp.hpl.jena.shared.Lock" %>
|
|
||||||
<%@ page import="com.thoughtworks.xstream.XStream" %>
|
|
||||||
<%@ page import="com.thoughtworks.xstream.io.xml.DomDriver" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission" %>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field" %>
|
|
||||||
<%@ page import="java.io.StringReader" %>
|
|
||||||
<%@ page import="java.util.*" %>
|
|
||||||
<%@ page import="java.util.Map" %>
|
|
||||||
<%@ page import="java.util.Iterator" %>
|
|
||||||
<%@page import="org.apache.commons.logging.LogFactory"%>
|
|
||||||
<%@page import="org.apache.commons.logging.Log"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
|
|
||||||
<%@page import="java.io.InputStream"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.FileItemIterator"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.FileItemStream"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.util.Streams"%>
|
|
||||||
<%@page import="com.hp.hpl.jena.rdf.model.Property"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
|
|
||||||
<%@page import="java.io.File"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.FileItem"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.FileItemFactory"%>
|
|
||||||
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor"%>
|
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
|
||||||
<%@ page import="java.net.URLDecoder" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.InsertException"%>
|
|
||||||
|
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
|
||||||
|
|
||||||
<%-- 2nd prototype of processing.
|
|
||||||
|
|
||||||
This one takes two lists of n3, on required and one optional. If
|
|
||||||
all of the variables in the required n3 are not bound or it cannot
|
|
||||||
be processed as n3 by Jena then it is an error in processing the form.
|
|
||||||
The optional n3 blocks will proccessed if their variables are bound and
|
|
||||||
are well formed.
|
|
||||||
--%>
|
|
||||||
|
|
||||||
<%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %>
|
|
||||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscellaneousPages" %>
|
|
||||||
<% request.setAttribute("requestedActions", new UseMiscellaneousPages()); %>
|
|
||||||
<vitro:confirmAuthorization />
|
|
||||||
|
|
||||||
<%
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
|
|
||||||
/* the post parameters seem to get consumed by the parsing so
|
|
||||||
* we have to make a copy. */
|
|
||||||
Map <String,String[]> queryParameters = null;
|
|
||||||
queryParameters = vreq.getParameterMap();
|
|
||||||
|
|
||||||
List<String> errorMessages = new ArrayList<String>();
|
|
||||||
|
|
||||||
//this version has been removed from the updated code
|
|
||||||
//EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq,queryParameters);
|
|
||||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session, request);
|
|
||||||
if( editConfig == null ){
|
|
||||||
%><jsp:forward page="/edit/messages/noEditConfigFound.jsp"/><%
|
|
||||||
}
|
|
||||||
EditN3Generator n3Subber = editConfig.getN3Generator();
|
|
||||||
EditSubmission submission = new EditSubmission(queryParameters,editConfig);
|
|
||||||
|
|
||||||
// Preprocess the form submission
|
|
||||||
// RY clone() creates a shallow copy, not a deep copy. To do this, need to implement
|
|
||||||
// a custom clone() method for EditSubmission or a copy constructor.
|
|
||||||
//EditSubmission submission = submission.clone();
|
|
||||||
//for (EditSubmissionPreprocessor preprocessor : editConfig.getEditSubmissionPreprocessors()) {
|
|
||||||
// preprocessor.preprocess(submission);
|
|
||||||
//}
|
|
||||||
|
|
||||||
/* entity to return to may be a variable */
|
|
||||||
List<String> entToReturnTo = new ArrayList<String>(1);
|
|
||||||
if( editConfig.getEntityToReturnTo() != null ){
|
|
||||||
entToReturnTo.add(" "+editConfig.getEntityToReturnTo()+" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String,String> errors = submission.getValidationErrors();
|
|
||||||
EditSubmission.putEditSubmissionInSession(session,submission);
|
|
||||||
|
|
||||||
if( errors != null && ! errors.isEmpty() ){
|
|
||||||
String form = editConfig.getFormUrl();
|
|
||||||
vreq.setAttribute("formUrl", form);
|
|
||||||
vreq.setAttribute("view", vreq.getParameter("view"));
|
|
||||||
%>
|
|
||||||
<jsp:forward page="${formUrl}" />
|
|
||||||
<%
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OntModel queryModel = editConfig.getQueryModelSelector().getModel(request,application);
|
|
||||||
OntModel resourcesModel = editConfig.getResourceModelSelector().getModel(request,application);
|
|
||||||
|
|
||||||
List<Model> requiredAssertions = null;
|
|
||||||
List<Model> requiredRetractions = null;
|
|
||||||
List<Model> optionalAssertions = null;
|
|
||||||
|
|
||||||
boolean requestIsAnUpdate = editConfig.getObject() != null && editConfig.getObject().trim().length() > 0;
|
|
||||||
if( requestIsAnUpdate ){
|
|
||||||
//handle update of an existing object
|
|
||||||
if( log.isDebugEnabled()) log.debug("editing an existing resource: " + editConfig.getObject() );
|
|
||||||
|
|
||||||
Map<String,List<String>> fieldAssertions = fieldsToAssertionMap(editConfig.getFields());
|
|
||||||
Map<String,List<String>> fieldRetractions= fieldsToRetractionMap(editConfig.getFields());
|
|
||||||
|
|
||||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues( submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions);
|
|
||||||
if(log.isDebugEnabled()) logAddRetract("substituted in literals from form",fieldAssertions,fieldRetractions);
|
|
||||||
entToReturnTo = n3Subber.subInUris(submission.getUrisFromForm(),entToReturnTo);
|
|
||||||
//fieldRetractions does NOT get values from form.
|
|
||||||
|
|
||||||
/* ****************** URIs and Literals in Scope ************** */
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(editConfig.getUrisInScope(), editConfig.getLiteralsInScope(), fieldAssertions );
|
|
||||||
fieldRetractions = n3Subber.substituteIntoValues(editConfig.getUrisInScope(), editConfig.getLiteralsInScope(), fieldRetractions);
|
|
||||||
if(log.isDebugEnabled()) logAddRetract("substituted in URIs and Literals from scope",fieldAssertions,fieldRetractions);
|
|
||||||
entToReturnTo = n3Subber.subInUris(editConfig.getUrisInScope(),entToReturnTo);
|
|
||||||
|
|
||||||
//do edits ever need new resources? (YES)
|
|
||||||
Map<String,String> varToNewResource = newToUriMap(editConfig.getNewResources(),wdf);
|
|
||||||
fieldAssertions = n3Subber.substituteIntoValues(varToNewResource, null, fieldAssertions);
|
|
||||||
if(log.isDebugEnabled()) logAddRetract("substituted in URIs for new resources",fieldAssertions,fieldRetractions);
|
|
||||||
entToReturnTo = n3Subber.subInUris(varToNewResource,entToReturnTo);
|
|
||||||
//fieldRetractions does NOT get values from form.
|
|
||||||
|
|
||||||
//editing an existing statement
|
|
||||||
List<Model> requiredFieldAssertions = new ArrayList<Model>();
|
|
||||||
List<Model> requiredFieldRetractions = new ArrayList<Model>();
|
|
||||||
for(String fieldName: fieldAssertions.keySet()){
|
|
||||||
Field field = editConfig.getFields().get(fieldName);
|
|
||||||
|
|
||||||
/* CHECK that field changed, then add assertions and retractions */
|
|
||||||
|
|
||||||
// No longer checking if field has changed, because assertions and retractions
|
|
||||||
// are mutually diffed before statements are added to or removed from the model.
|
|
||||||
// The explicit change check can cause problems
|
|
||||||
// in more complex setups, like the automatic form building in DataStaR.
|
|
||||||
|
|
||||||
if (true) { // ( hasFieldChanged(fieldName, editConfig, submission) ){
|
|
||||||
//log.debug("field "+fieldName+" has changed ...");
|
|
||||||
/* if the field was a checkbox then we need to something special */
|
|
||||||
|
|
||||||
List<String> assertions = fieldAssertions.get(fieldName);
|
|
||||||
List<String> retractions = fieldRetractions.get(fieldName);
|
|
||||||
for( String n3 : assertions){
|
|
||||||
try{
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredFieldAssertions.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
String errMsg = "error processing N3 assertion string from field " + fieldName + "\n"+
|
|
||||||
t.getMessage() + '\n' + "n3: \n" + n3;
|
|
||||||
errorMessages.add(errMsg);
|
|
||||||
if ( log.isDebugEnabled() ) {
|
|
||||||
log.debug( errMsg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for( String n3 : retractions ){
|
|
||||||
try{
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredFieldRetractions.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
String errMsg = "error processing N3 retraction string from field " + fieldName + "\n"+
|
|
||||||
t.getMessage() + '\n' +
|
|
||||||
"n3: \n" + n3;
|
|
||||||
errorMessages.add(errMsg);
|
|
||||||
if ( log.isDebugEnabled() ) {
|
|
||||||
log.debug( errMsg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
requiredAssertions = requiredFieldAssertions;
|
|
||||||
requiredRetractions = requiredFieldRetractions;
|
|
||||||
optionalAssertions = Collections.EMPTY_LIST;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if( log.isDebugEnabled()) log.debug("creating a new relation " + editConfig.getPredicateUri() );
|
|
||||||
//handle creation of a new object property and maybe a resource
|
|
||||||
List<String> n3Required = editConfig.getN3Required();
|
|
||||||
List<String> n3Optional = editConfig.getN3Optional();
|
|
||||||
|
|
||||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
|
||||||
//sub in resource uris off form
|
|
||||||
n3Required = n3Subber.subInUris(submission.getUrisFromForm(), n3Required);
|
|
||||||
n3Optional = n3Subber.subInUris(submission.getUrisFromForm(), n3Optional);
|
|
||||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in URIs off from ",n3Required,n3Optional);
|
|
||||||
entToReturnTo = n3Subber.subInUris(submission.getUrisFromForm(), entToReturnTo);
|
|
||||||
|
|
||||||
//sub in literals from form
|
|
||||||
n3Required = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Required);
|
|
||||||
n3Optional = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Optional);
|
|
||||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in literals off from ",n3Required,n3Optional);
|
|
||||||
|
|
||||||
/* ****************** URIs and Literals in Scope ************** */
|
|
||||||
n3Required = n3Subber.subInUris( editConfig.getUrisInScope(), n3Required);
|
|
||||||
n3Optional = n3Subber.subInUris( editConfig.getUrisInScope(), n3Optional);
|
|
||||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in URIs from scope ",n3Required,n3Optional);
|
|
||||||
entToReturnTo = n3Subber.subInUris(editConfig.getUrisInScope(), entToReturnTo);
|
|
||||||
|
|
||||||
n3Required = n3Subber.subInLiterals( editConfig.getLiteralsInScope(), n3Required);
|
|
||||||
n3Optional = n3Subber.subInLiterals( editConfig.getLiteralsInScope(), n3Optional);
|
|
||||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in Literals from scope ",n3Required,n3Optional);
|
|
||||||
|
|
||||||
/* ****************** New Resources ********************** */
|
|
||||||
Map<String,String> varToNewResource = newToUriMap(editConfig.getNewResources(),wdf);
|
|
||||||
|
|
||||||
//if we are editing an existing prop, no new resources will be substituted since the var will
|
|
||||||
//have already been substituted in by urisInScope.
|
|
||||||
n3Required = n3Subber.subInUris( varToNewResource, n3Required);
|
|
||||||
n3Optional = n3Subber.subInUris( varToNewResource, n3Optional);
|
|
||||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in URIs for new resources ",n3Required,n3Optional);
|
|
||||||
entToReturnTo = n3Subber.subInUris(varToNewResource, entToReturnTo);
|
|
||||||
|
|
||||||
//deal with required N3
|
|
||||||
List<Model> requiredNewModels = new ArrayList<Model>();
|
|
||||||
for(String n3 : n3Required){
|
|
||||||
try{
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
requiredNewModels.add( model );
|
|
||||||
}catch(Throwable t){
|
|
||||||
errorMessages.add("error processing required n3 string \n"+
|
|
||||||
t.getMessage() + '\n' +
|
|
||||||
"n3: \n" + n3 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !errorMessages.isEmpty() ){
|
|
||||||
|
|
||||||
String error = "problems processing required n3: \n";
|
|
||||||
for( String errorMsg : errorMessages){
|
|
||||||
error += errorMsg + '\n';
|
|
||||||
}
|
|
||||||
throw new JspException("errors processing required N3,\n" + error );
|
|
||||||
}
|
|
||||||
requiredAssertions = requiredNewModels;
|
|
||||||
requiredRetractions = Collections.EMPTY_LIST;
|
|
||||||
|
|
||||||
//deal with optional N3
|
|
||||||
List<Model> optionalNewModels = new ArrayList<Model>();
|
|
||||||
for(String n3 : n3Optional){
|
|
||||||
try{
|
|
||||||
Model model = ModelFactory.createDefaultModel();
|
|
||||||
StringReader reader = new StringReader(n3);
|
|
||||||
model.read(reader, "", "N3");
|
|
||||||
optionalNewModels.add(model);
|
|
||||||
}catch(Throwable t){
|
|
||||||
errorMessages.add("error processing optional n3 string \n"+
|
|
||||||
t.getMessage() + '\n' +
|
|
||||||
"n3: \n" + n3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
optionalAssertions = optionalNewModels;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//The requiredNewModels and the optionalNewModels could be handled differently
|
|
||||||
//but for now we'll just do them the same
|
|
||||||
requiredAssertions.addAll(optionalAssertions);
|
|
||||||
|
|
||||||
//************************************************************
|
|
||||||
//make a model with all the assertions and a model with all the
|
|
||||||
//retractions, do a diff on those and then only add those to the
|
|
||||||
//jenaOntModel
|
|
||||||
//************************************************************
|
|
||||||
|
|
||||||
Model allPossibleAssertions = ModelFactory.createDefaultModel();
|
|
||||||
Model allPossibleRetractions = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
for( Model model : requiredAssertions ) {
|
|
||||||
allPossibleAssertions.add( model );
|
|
||||||
}
|
|
||||||
for( Model model : requiredRetractions ){
|
|
||||||
allPossibleRetractions.add( model );
|
|
||||||
}
|
|
||||||
|
|
||||||
Model actualAssertions = allPossibleAssertions.difference( allPossibleRetractions );
|
|
||||||
Model actualRetractions = allPossibleRetractions.difference( allPossibleAssertions );
|
|
||||||
|
|
||||||
if( editConfig.isUseDependentResourceDelete() ){
|
|
||||||
Model depResRetractions =
|
|
||||||
DependentResourceDeleteJena
|
|
||||||
.getDependentResourceDeleteForChange(actualAssertions,actualRetractions,queryModel);
|
|
||||||
actualRetractions.add( depResRetractions );
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ModelChangePreprocessor> modelChangePreprocessors = editConfig.getModelChangePreprocessors();
|
|
||||||
if ( modelChangePreprocessors != null ) {
|
|
||||||
for ( ModelChangePreprocessor pp : modelChangePreprocessors ) {
|
|
||||||
pp.preprocess( actualRetractions, actualAssertions, request );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the model to write to here in case a preprocessor has switched the write layer
|
|
||||||
OntModel writeModel = editConfig.getWriteModelSelector().getModel(request,application);
|
|
||||||
|
|
||||||
String editorUri = EditN3Utils.getEditorUri(vreq);
|
|
||||||
Lock lock = null;
|
|
||||||
try{
|
|
||||||
lock = writeModel.getLock();
|
|
||||||
lock.enterCriticalSection(Lock.WRITE);
|
|
||||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,true));
|
|
||||||
writeModel.add( actualAssertions );
|
|
||||||
writeModel.remove( actualRetractions );
|
|
||||||
}catch(Throwable t){
|
|
||||||
errorMessages.add("error adding edit change n3required model to in memory model \n"+ t.getMessage() );
|
|
||||||
}finally{
|
|
||||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,false));
|
|
||||||
lock.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( entToReturnTo.size() >= 1 && entToReturnTo.get(0) != null){
|
|
||||||
request.setAttribute("entityToReturnTo",
|
|
||||||
entToReturnTo.get(0).trim().replaceAll("<","").replaceAll(">",""));
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
|
|
||||||
<jsp:forward page="postEditCleanUp.jsp"/>
|
|
||||||
|
|
||||||
<%!
|
|
||||||
|
|
||||||
/* ********************************************************* */
|
|
||||||
/* ******************** utility functions ****************** */
|
|
||||||
/* ********************************************************* */
|
|
||||||
|
|
||||||
public Map<String,List<String>> fieldsToAssertionMap( Map<String,Field> fields){
|
|
||||||
Map<String,List<String>> out = new HashMap<String,List<String>>();
|
|
||||||
for( String fieldName : fields.keySet()){
|
|
||||||
Field field = fields.get(fieldName);
|
|
||||||
|
|
||||||
List<String> copyOfN3 = new ArrayList<String>();
|
|
||||||
for( String str : field.getAssertions()){
|
|
||||||
copyOfN3.add(str);
|
|
||||||
}
|
|
||||||
out.put( fieldName, copyOfN3 );
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String,List<String>> fieldsToRetractionMap( Map<String,Field> fields){
|
|
||||||
Map<String,List<String>> out = new HashMap<String,List<String>>();
|
|
||||||
for( String fieldName : fields.keySet()){
|
|
||||||
Field field = fields.get(fieldName);
|
|
||||||
|
|
||||||
List<String> copyOfN3 = new ArrayList<String>();
|
|
||||||
for( String str : field.getRetractions()){
|
|
||||||
copyOfN3.add(str);
|
|
||||||
}
|
|
||||||
out.put( fieldName, copyOfN3 );
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ******************** Utility methods ********************** */
|
|
||||||
|
|
||||||
public Map<String,String> newToUriMap(Map<String,String> newResources, WebappDaoFactory wdf){
|
|
||||||
HashMap<String,String> newVarsToUris = new HashMap<String,String>();
|
|
||||||
HashSet<String> newUris = new HashSet<String>();
|
|
||||||
for( String key : newResources.keySet()){
|
|
||||||
String prefix = newResources.get(key);
|
|
||||||
String uri = makeNewUri(prefix, wdf);
|
|
||||||
while( newUris.contains(uri) ){
|
|
||||||
uri = makeNewUri(prefix,wdf);
|
|
||||||
}
|
|
||||||
newVarsToUris.put(key,uri);
|
|
||||||
newUris.add(uri);
|
|
||||||
}
|
|
||||||
return newVarsToUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String makeNewUri(String prefix, WebappDaoFactory wdf){
|
|
||||||
if( prefix == null || prefix.length() == 0 ){
|
|
||||||
String uri = null;
|
|
||||||
try{
|
|
||||||
uri = wdf.getIndividualDao().getUnusedURI(null);
|
|
||||||
}catch(InsertException ex){
|
|
||||||
log.error("could not create uri");
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
String goodURI = null;
|
|
||||||
int attempts = 0;
|
|
||||||
while( goodURI == null && attempts < 30 ){
|
|
||||||
Individual ind = new IndividualImpl();
|
|
||||||
ind.setURI( prefix + random.nextInt() );
|
|
||||||
try{
|
|
||||||
goodURI = wdf.getIndividualDao().getUnusedURI(ind);
|
|
||||||
}catch(InsertException ex){
|
|
||||||
log.debug("could not create uri");
|
|
||||||
}
|
|
||||||
attempts++;
|
|
||||||
}
|
|
||||||
if( goodURI == null )
|
|
||||||
log.error("could not create uri for prefix " + prefix);
|
|
||||||
return goodURI;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Random random = new Random();
|
|
||||||
|
|
||||||
//we should get this from the application
|
|
||||||
static String defaultUriPrefix = "http://vivo.library.cornell.edu/ns/0.1#individual";
|
|
||||||
public static final String baseDirectoryForFiles = "/usr/local/vitrofiles";
|
|
||||||
|
|
||||||
private static Property RDF_TYPE = ResourceFactory.createProperty(VitroVocabulary.RDF_TYPE);
|
|
||||||
private static Property RDFS_LABEL = ResourceFactory.createProperty(VitroVocabulary.RDFS+"label");
|
|
||||||
|
|
||||||
Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.edit.processRdfForm2.jsp");
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%!
|
|
||||||
/* What are the posibilities and what do they mean?
|
|
||||||
field is a Uri:
|
|
||||||
orgValue formValue
|
|
||||||
null null Optional object property, maybe a un-filled out checkbox or radio button.
|
|
||||||
non-null null There was an object property and it was unset on the form
|
|
||||||
null non-null There was an objProp that was not set and is now set.
|
|
||||||
non-null non-null If they are the same then there was no edit, if the differ then form field was changed
|
|
||||||
|
|
||||||
field is a Literal:
|
|
||||||
orgValue formValue
|
|
||||||
null null Optional value that was not set.
|
|
||||||
non-null null Optional value that was unset on form
|
|
||||||
null non-null Optional value that was unset but was set on form
|
|
||||||
non-null non-null If same, there was no edit, if different, there was a change to the form field.
|
|
||||||
|
|
||||||
What about checkboxes?
|
|
||||||
*/
|
|
||||||
private boolean hasFieldChanged(String fieldName, EditConfiguration editConfig, EditSubmission submission) {
|
|
||||||
String orgValue = editConfig.getUrisInScope().get(fieldName);
|
|
||||||
String newValue = submission.getUrisFromForm().get(fieldName);
|
|
||||||
|
|
||||||
// see possibilities list in comments just above
|
|
||||||
if (orgValue == null && newValue != null) {
|
|
||||||
log.debug("Note: Setting previously null object property for field '"+fieldName+"' to new value ["+newValue+"]");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( orgValue != null && newValue != null){
|
|
||||||
if( orgValue.equals(newValue))
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This does NOT use the semantics of the literal's Datatype or the language.
|
|
||||||
Literal orgLit = editConfig.getLiteralsInScope().get(fieldName);
|
|
||||||
Literal newLit = submission.getLiteralsFromForm().get(fieldName);
|
|
||||||
|
|
||||||
if( orgLit != null ) {
|
|
||||||
orgValue = orgLit.getValue().toString();
|
|
||||||
}
|
|
||||||
if( newLit != null ) {
|
|
||||||
newValue = newLit.getValue().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// added for links, where linkDisplayRank will frequently come in null
|
|
||||||
if (orgValue == null && newValue != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( orgValue != null && newValue != null ){
|
|
||||||
if( orgValue.equals(newValue)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//value wasn't set originally because the field is optional
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean logAddRetract(String msg, Map<String,List<String>>add, Map<String,List<String>>retract){
|
|
||||||
log.debug(msg);
|
|
||||||
if( add != null ) log.debug( "assertions: " + add.toString() );
|
|
||||||
if( retract != null ) log.debug( "retractions: " + retract.toString() );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean logRequiredOpt(String msg, List<String>required, List<String>optional){
|
|
||||||
log.debug(msg);
|
|
||||||
if( required != null ) log.debug( "required: " + required.toString() );
|
|
||||||
if( optional != null ) log.debug( "optional: " + optional.toString() );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dump(String name, Object fff){
|
|
||||||
XStream xstream = new XStream(new DomDriver());
|
|
||||||
System.out.println( "*******************************************************************" );
|
|
||||||
System.out.println( name );
|
|
||||||
System.out.println(xstream.toXML( fff ));
|
|
||||||
}
|
|
||||||
%>
|
|
Loading…
Add table
Reference in a new issue