Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.
This commit is contained in:
commit
4f2e303079
1839 changed files with 235630 additions and 0 deletions
107
webapp/web/edit/dashboardPropsList.jsp
Normal file
107
webapp/web/edit/dashboardPropsList.jsp
Normal file
|
@ -0,0 +1,107 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
||||
<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/PropertyEditLink" prefix="edLnk" %>
|
||||
<%@ 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.beans.Property" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.KeywordProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao" %>
|
||||
<%@ page import="java.util.ArrayList" %>
|
||||
<%@ page import="org.apache.commons.logging.Log" %>
|
||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
|
||||
<jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.dashboardPropsList.jsp");
|
||||
%>
|
||||
<%
|
||||
boolean showSelfEdits=false;
|
||||
boolean showCuratorEdits=false;
|
||||
if( VitroRequestPrep.isSelfEditing(request) ) {
|
||||
showSelfEdits=true;
|
||||
log.debug("self editing active");
|
||||
} else {
|
||||
log.debug("self editing inactive");
|
||||
}
|
||||
if (loginHandler!=null && loginHandler.getLoginStatus()=="authenticated" && Integer.parseInt(loginHandler.getLoginRole())>=loginHandler.getEditor()) {
|
||||
showCuratorEdits=true;
|
||||
log.debug("curator editing active");
|
||||
} else {
|
||||
log.debug("curator editing inactive");
|
||||
}%>
|
||||
<c:set var='entity' value='${requestScope.entity}'/><%-- just moving this into page scope for easy use --%>
|
||||
<c:set var='portal' value='${requestScope.portalBean}'/><%-- likewise --%>
|
||||
<%
|
||||
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>
|
||||
<% }
|
||||
}%>
|
||||
|
152
webapp/web/edit/editDatapropStmtRequestDispatch.jsp
Normal file
152
webapp/web/edit/editDatapropStmtRequestDispatch.jsp
Normal file
|
@ -0,0 +1,152 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %>
|
||||
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %>
|
||||
<%@ page import="java.util.HashMap" %>
|
||||
<%
|
||||
org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch");
|
||||
//Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch");
|
||||
%>
|
||||
<%
|
||||
// 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";
|
||||
|
||||
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
|
||||
%> <c:redirect url="<%= Controllers.LOGIN %>" /> <%
|
||||
}
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
if( EditConfiguration.getEditKey( vreq ) == null ){
|
||||
vreq.setAttribute("editKey",EditConfiguration.newEditKey(session));
|
||||
}else{
|
||||
vreq.setAttribute("editKey", EditConfiguration.getEditKey( vreq ));
|
||||
}
|
||||
|
||||
String subjectUri = vreq.getParameter("subjectUri");
|
||||
String predicateUri = vreq.getParameter("predicateUri");
|
||||
String formParam = vreq.getParameter("editForm");
|
||||
String command = vreq.getParameter("cmd");
|
||||
|
||||
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");
|
||||
}
|
||||
vreq.setAttribute("subjectUri", subjectUri);
|
||||
vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri));
|
||||
vreq.setAttribute("predicateUri", predicateUri);
|
||||
vreq.setAttribute("predicateUriJson", MiscWebUtils.escape(predicateUri));
|
||||
|
||||
/* since we have the URIs let's put the individual, data property, and optional data property statement in the request */
|
||||
|
||||
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("editDatapropStmtRequest.jsp: Could not find subject Individual in model: '" + subjectUri + "'");
|
||||
}
|
||||
vreq.setAttribute("subject", subject);
|
||||
|
||||
DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||
if( dataproperty == null ) {
|
||||
log.error("Could not find data property '"+predicateUri+"' in model");
|
||||
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
|
||||
}
|
||||
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) {
|
||||
dps = RdfLiteralHash.getDataPropertyStmtByHash( subject ,dataHash);
|
||||
|
||||
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() ){
|
||||
log.debug("predicate for DataProperty from request is " + dataproperty.getURI() + " with rangeDatatypeUri of '" + dataproperty.getRangeDatatypeURI() + "'");
|
||||
if( dps == null )
|
||||
log.debug("no exisitng 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;
|
||||
}
|
||||
|
||||
if( formParam == null ){
|
||||
String 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);
|
||||
} else {
|
||||
vreq.setAttribute("form", formParam);
|
||||
}
|
||||
|
||||
if( session.getAttribute("requestedFromEntity") == null )
|
||||
session.setAttribute("requestedFromEntity", subjectUri );
|
||||
%>
|
||||
<jsp:forward page="/edit/forms/${form}" />
|
247
webapp/web/edit/editRequestDispatch.jsp
Normal file
247
webapp/web/edit/editRequestDispatch.jsp
Normal file
|
@ -0,0 +1,247 @@
|
|||
<%-- $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.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.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %>
|
||||
<%@ 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");
|
||||
%>
|
||||
<%
|
||||
/*
|
||||
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";
|
||||
|
||||
request.getSession(true);
|
||||
|
||||
if (!VitroRequestPrep.isSelfEditing(request)
|
||||
&& !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
|
||||
%> <c:redirect url="<%= Controllers.LOGIN %>" /> <%
|
||||
}
|
||||
|
||||
String editKey = (EditConfiguration.getEditKey(request) == null)
|
||||
? EditConfiguration.newEditKey(session)
|
||||
: EditConfiguration.getEditKey(request);
|
||||
request.setAttribute("editKey", editKey);
|
||||
|
||||
// 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 determin 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 && formParam == null)
|
||||
// throw new Error("In editRequestDispatch.jsp, could not find subject in model: '"
|
||||
// + 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)) ) {
|
||||
%><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 ){
|
||||
objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||
request.setAttribute("predicate", objectProp);
|
||||
|
||||
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 (customForm != null && customForm.length() > 0) {
|
||||
//bdc34: maybe this should be the custom form on the class, not the property.
|
||||
form = objectProp.getCustomEntryForm();
|
||||
} else {
|
||||
//If a objectProperty is both provideSelect and offerCreateNewOption
|
||||
// and a user gos 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;
|
||||
}
|
||||
|
||||
request.setAttribute("form", form);
|
||||
%>
|
||||
<jsp:forward page="/edit/forms/${form}"/>
|
||||
|
||||
<%!
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
%>
|
14
webapp/web/edit/fileUploadError.jsp
Normal file
14
webapp/web/edit/fileUploadError.jsp
Normal file
|
@ -0,0 +1,14 @@
|
|||
<%-- $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" />
|
85
webapp/web/edit/formPrefix.jsp
Normal file
85
webapp/web/edit/formPrefix.jsp
Normal file
|
@ -0,0 +1,85 @@
|
|||
<%-- $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.filters.VitroRequestPrep"%>
|
||||
|
||||
<c:set var='themeDir'><c:out value='${portalBean.themeDir}'/></c:set>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head> <!-- formPrefix.jsp -->
|
||||
<%
|
||||
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>
|
||||
<% } %>
|
||||
|
||||
<script language="javascript" type="text/javascript" src="../js/jquery.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="../js/jquery_plugins/jquery.bgiframe.pack.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="../js/jquery_plugins/thickbox/thickbox-compressed.js"></script>
|
||||
<!-- <script language="javascript" type="text/javascript" src="../js/jquery_plugins/ui.datepicker.js"></script> -->
|
||||
<script language="javascript" type="text/javascript" src="../js/jquery_plugins/jquery-autocomplete/jquery.autocomplete.pack.js"></script>
|
||||
|
||||
<% String useAutoComplete = (useAutoComplete=request.getParameter("useAutoComplete")) != null && !(useAutoComplete.equals("")) ? useAutoComplete : "false";
|
||||
if (useAutoComplete.equalsIgnoreCase("true")) { %>
|
||||
<link rel="stylesheet" type="text/css" href="../js/jquery_plugins/jquery-autocomplete/jquery.autocomplete.css"/>
|
||||
<% } %>
|
||||
|
||||
<!-- <link rel="stylesheet" type="text/css" href="../js/jquery_plugins/ui.datepicker.css"/> -->
|
||||
<link rel="stylesheet" type="text/css" href="../js/jquery_plugins/thickbox/thickbox.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="<c:url value="/${themeDir}css/screen.css"/>" media="screen"/>
|
||||
<link rel="stylesheet" type="text/css" href="<c:url value="/${themeDir}css/formedit.css" />" media="screen"/>
|
||||
|
||||
<title>Edit</title>
|
||||
</head>
|
||||
<body class="formsEdit">
|
||||
<div id="wrap" class="container">
|
||||
<jsp:include page="/${themeDir}jsp/identity.jsp" flush="true"/>
|
||||
<jsp:include page="/${themeDir}jsp/menu.jsp" flush="true"/>
|
||||
<div id="contentwrap">
|
||||
<div id="content" class="form">
|
||||
<!-- end of formPrefix.jsp -->
|
17
webapp/web/edit/formSuffix.jsp
Normal file
17
webapp/web/edit/formSuffix.jsp
Normal file
|
@ -0,0 +1,17 @@
|
|||
<%-- $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.filters.VitroRequestPrep"%>
|
||||
|
||||
<c:set var='themeDir'><c:out value='${portalBean.themeDir}' /></c:set>
|
||||
</div> <!-- #content.form -->
|
||||
|
||||
</div>
|
||||
<div class="push"></div>
|
||||
|
||||
<jsp:include page="/${themeDir}jsp/footer.jsp" flush="true"/>
|
||||
|
||||
</div><!-- end wrap -->
|
||||
|
||||
</body>
|
||||
</html>
|
270
webapp/web/edit/forms/addMissingWithMonikerAndLink.jsp
Normal file
270
webapp/web/edit/forms/addMissingWithMonikerAndLink.jsp
Normal file
|
@ -0,0 +1,270 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ 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.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
|
||||
if (prop == null) throw new Error("no object property specified via incoming predicate attribute in defaultAddMissingIndividualForm.jsp");
|
||||
String propDomainPublic = (prop.getDomainPublic() == null) ? "affiliation" : prop.getDomainPublic();
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
//String contextPath = vreq.getContextPath();
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
if( prop.getRangeVClassURI() == null )throw new Error("Property has null for its range class URI");
|
||||
|
||||
VClass rangeClass = wdf.getVClassDao().getVClassByURI(prop.getRangeVClassURI());
|
||||
if( rangeClass == null ) throw new Error ("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
|
||||
//vreq.setAttribute("rangeClassLocalName",rangeClass.getLocalName());
|
||||
//vreq.setAttribute("rangeClassNamespace",rangeClass.getNamespace());
|
||||
vreq.setAttribute("rangeClassUri",prop.getRangeVClassURI());
|
||||
vreq.setAttribute("curatorReviewUri","http://vivo.library.cornell.edu/ns/0.1#CuratorReview");
|
||||
|
||||
//get the current portal and make this new individual a member of that portal
|
||||
vreq.setAttribute("portalUri", vreq.getPortal().getTypeUri());
|
||||
%>
|
||||
|
||||
<v:jsonset var="queryForInverse" >
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
SELECT ?inverse_property
|
||||
WHERE { ?inverse_property owl:inverseOf ?predicate }
|
||||
</v:jsonset>
|
||||
|
||||
<%-- Enter here the class names to be used for constructing MONIKERS_VIA_VCLASS pick lists
|
||||
These are then referenced in the field's ObjectClassUri but not elsewhere.
|
||||
Note that you can't reference a jsonset variable inside another jsonset expression
|
||||
or you get double escaping problems --%>
|
||||
<v:jsonset var="newIndividualVClassUri">${rangeClassUri}</v:jsonset>
|
||||
|
||||
<%-- Then enter a SPARQL query for each field, by convention concatenating the field id with "Existing"
|
||||
to convey that the expression is used to retrieve any existing value for the field in an existing individual.
|
||||
Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below
|
||||
and in the literalsOnForm --%>
|
||||
<v:jsonset var="nameExisting" >
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
SELECT ?existingName
|
||||
WHERE { ?newIndividual rdfs:label ?existingName }
|
||||
</v:jsonset>
|
||||
<%-- Pair the "existing" query with the skeleton of what will be asserted for a new statement involving this field.
|
||||
the actual assertion inserted in the model will be created via string substitution into the ? variables.
|
||||
NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%>
|
||||
<v:jsonset var="nameAssertion" >
|
||||
@prefix vivo: <http://vivo.library.cornell.edu/ns/0.1#> .
|
||||
?newIndividual rdfs:label ?name .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="monikerExisting" >
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
SELECT ?existingMoniker
|
||||
WHERE { ?newIndividual vitro:moniker ?existingMoniker }
|
||||
</v:jsonset>
|
||||
<v:jsonset var="monikerAssertion" >
|
||||
@prefix vivo: <http://vivo.library.cornell.edu/ns/0.1#> .
|
||||
?newIndividual vitro:moniker ?moniker .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="linkUrlExisting" >
|
||||
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
|
||||
SELECT ?existingLinkUrl
|
||||
WHERE { ?newIndividual vitro:primaryLink ?newLink ;
|
||||
?newLink vitro:linkURL ?existingLinkUrl .
|
||||
}
|
||||
</v:jsonset>
|
||||
<v:jsonset var="linkUrlAssertion" >
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
?newLink vitro:linkURL ?linkUrl .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
@prefix vivo: <http://vivo.library.cornell.edu/ns/0.1#> .
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
|
||||
?newIndividual rdf:type <${curatorReviewUri}> .
|
||||
?newIndividual rdf:type <${rangeClassUri}> .
|
||||
?subject ?predicate ?newIndividual .
|
||||
|
||||
?newIndividual rdfs:label ?name .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3Inverse" >
|
||||
?newIndividual ?inverseProp ?subject .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- make sure you have all the @prefix entries to cover the statements in each block --%>
|
||||
<v:jsonset var="n3optional" >
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
?newIndividual vitro:moniker ?moniker .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- set the portal of the new individual to the current portal. --%>
|
||||
<v:jsonset var="n3portal">
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
?newIndividual rdf:type <${portalUri}> .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- note that it's safer to have multiple distinct optional blocks so that a failure in one
|
||||
will not prevent correct sections from being inserted --%>
|
||||
<v:jsonset var="n3link" >
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
?newLink
|
||||
rdf:type vitro:Link ;
|
||||
vitro:linkURL ?linkUrl ;
|
||||
vitro:linkAnchor ?name ;
|
||||
vitro:linkDisplayRank "1" .
|
||||
|
||||
?newIndividual vitro:primaryLink ?newLink .
|
||||
</v:jsonset>
|
||||
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ],
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "newIndividual", "${objectUriJson}", "URI" ],
|
||||
|
||||
"n3required" : [ "${n3ForEdit}" ],
|
||||
"n3optional" : [ "${n3optional}", "${n3Inverse}", "${n3link}", "${n3portal}" ],
|
||||
"newResources" : {
|
||||
"newIndividual" : "http://vivo.library.cornell.edu/ns/0.1#individual",
|
||||
"newLink" : "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#Link"
|
||||
},
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
"urisOnForm" : [ ],
|
||||
"literalsOnForm" : [ "name","moniker","linkUrl" ],
|
||||
"filesOnForm" : [ ],
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { "inverseProp" : "${queryForInverse}" },
|
||||
"sparqlForExistingLiterals" : {
|
||||
"name" : "${nameExisting}",
|
||||
"moniker" : "${monikerExisting}",
|
||||
"linkUrl" : "${linkUrlExisting}"
|
||||
},
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : {
|
||||
"name" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${nameAssertion}" ]
|
||||
},
|
||||
"moniker" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ ],
|
||||
"optionsType" : "MONIKERS_VIA_VCLASS",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "${newIndividualVClassUri}",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${monikerAssertion}" ]
|
||||
},
|
||||
"linkUrl" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${linkUrlAssertion}" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
<%
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
|
||||
if( editConfig == null ){
|
||||
editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
}
|
||||
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
String objectUri = (String)request.getAttribute("objectUri");
|
||||
if( objectUri != null ){
|
||||
editConfig.prepareForObjPropUpdate(model);
|
||||
}else{
|
||||
editConfig.prepareForNonUpdate(model);
|
||||
}
|
||||
|
||||
String submitButtonLabel=""; // don't put local variables into the request
|
||||
/* title is used by pre and post form fragments */
|
||||
if (objectUri != null) {
|
||||
request.setAttribute("title", "Edit \""+propDomainPublic+"\" entry for " + subject.getName());
|
||||
submitButtonLabel = "Save changes";
|
||||
} else {
|
||||
request.setAttribute("title","Create a new \""+propDomainPublic+"\" entry for " + subject.getName());
|
||||
submitButtonLabel = "Create new \""+propDomainPublic+"\" entry";
|
||||
}
|
||||
|
||||
%>
|
||||
|
||||
<jsp:include page="${preForm}">
|
||||
<jsp:param name="useTinyMCE" value="false"/>
|
||||
<jsp:param name="useAutoComplete" value="true"/>
|
||||
</jsp:include>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(this).load($(this).parent().children('a').attr('src')+" .editForm");
|
||||
|
||||
$(document).ready(function() {
|
||||
var key = $("input[name='editKey']").attr("value");
|
||||
$.getJSON("<c:url value="/dataservice"/>", {getN3EditOptionList:"1", field: "moniker", editKey: key}, function(json){
|
||||
|
||||
$("select#moniker").replaceWith("<input type='text' id='moniker' name='moniker' />");
|
||||
|
||||
$("#moniker").autocomplete(json, {
|
||||
minChars: 0,
|
||||
width: 320,
|
||||
matchContains: true,
|
||||
mustMatch: 0,
|
||||
autoFill: false,
|
||||
formatItem: function(row, i, max) {
|
||||
return row[0];
|
||||
},
|
||||
formatMatch: function(row, i, max) {
|
||||
return row[0];
|
||||
},
|
||||
formatResult: function(row) {
|
||||
return row[0];
|
||||
}
|
||||
|
||||
}).result(function(event, data, formatted) {
|
||||
$("input#moniker").attr("value", data[1]);
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
</script>
|
||||
|
||||
<h2>${title}</h2>
|
||||
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
|
||||
<v:input type="text" label="name (required)" id="name" size="30"/>
|
||||
<hr/>
|
||||
<v:input type="select" label="label (optional)" id="moniker"/> <em>start typing to see existing choices, or add a new label</em>
|
||||
<v:input type="text" label="associated web page (optional)" id="linkUrl" size="50"/>
|
||||
<v:input type="submit" id="submit" value="<%=submitButtonLabel%>" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
118
webapp/web/edit/forms/admin/mayEditAs.jsp
Normal file
118
webapp/web/edit/forms/admin/mayEditAs.jsp
Normal file
|
@ -0,0 +1,118 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
|
||||
<%@ page import="org.apache.commons.logging.Log" %>
|
||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.admin.mayEditAs.jsp");
|
||||
public static String RANGE_CLASS = "http://xmlns.com/foaf/0.1/Agent";
|
||||
public static String PREDICATE = VitroVocabulary.MAY_EDIT_AS;
|
||||
%>
|
||||
<%
|
||||
String subjectUri = (String)request.getAttribute("subjectUri");
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
|
||||
VClass rangeClass = wdf.getVClassDao().getVClassByURI( RANGE_CLASS );
|
||||
if( rangeClass == null ) log.debug("Cannot find class for range for property."
|
||||
+ " Looking for " + RANGE_CLASS);
|
||||
request.setAttribute("rangeClassUriJson", MiscWebUtils.escape(RANGE_CLASS));
|
||||
|
||||
request.setAttribute("predicateUriJson", MiscWebUtils.escape(PREDICATE));
|
||||
%>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
?subject ?predicate ?objectVar.
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/userEdit",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ] ,
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "objectVar" , "${objectUriJson}" , "URI"],
|
||||
|
||||
"n3required" : [ "${n3ForEdit}" ],
|
||||
"n3optional" : [ ],
|
||||
"newResources" : { },
|
||||
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
|
||||
"urisOnForm" : ["objectVar"],
|
||||
"literalsOnForm" : [ ],
|
||||
"filesOnForm" : [ ],
|
||||
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { },
|
||||
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : { "objectVar" : {
|
||||
"newResource" : "false",
|
||||
"queryForExisting" : { },
|
||||
"validators" : [ ],
|
||||
"optionsType" : "INDIVIDUALS_VIA_VCLASS",
|
||||
"subjectUri" : "${subjectUriJson}",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "${rangeClassUriJson}",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"literalOptions" : [ ] ,
|
||||
"assertions" : ["${n3ForEdit}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<% /* now put edit configuration Json object into session */
|
||||
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
String formTitle ="";
|
||||
String submitLabel ="";
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
|
||||
editConfig.prepareForObjPropUpdate( model );
|
||||
formTitle = "Change person that user may edit as";
|
||||
submitLabel = "save change";
|
||||
} else {
|
||||
editConfig.prepareForNonUpdate( model );
|
||||
formTitle = "Add person that user may edit as";
|
||||
submitLabel = "add edit right";
|
||||
}
|
||||
%>
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
||||
<h2><%=formTitle%></h2>
|
||||
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" method="post">
|
||||
<v:input type="select" id="objectVar" size="80" />
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<c:if test="${!empty param.objectUri}" >
|
||||
<form class="deleteForm" action="<c:url value="/edit/n3Delete.jsp"/>" method="post">
|
||||
<label for="delete"><h3>Remove the right to edit as this person?</h3></label>
|
||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
|
||||
<input type="hidden" name="editform" value="edit/admin/mayEditAs.jsp"/>
|
||||
<v:input type="submit" id="delete" value="Remove" cancel="" />
|
||||
</form>
|
||||
</c:if>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
135
webapp/web/edit/forms/admin/resourceDisplayVisibility.jsp
Normal file
135
webapp/web/edit/forms/admin/resourceDisplayVisibility.jsp
Normal file
|
@ -0,0 +1,135 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="org.apache.commons.logging.Log" %>
|
||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.admin.resourceDisplayVisibility.jsp");
|
||||
%>
|
||||
<% /* Here is the calling form, as implemented for props_edit.jsp */
|
||||
// <form action="edit/editRequestDispatch.jsp" method="get"> */
|
||||
// <input name="home" type="hidden" value="${portalBean.portalId}" />
|
||||
// <input name="subjectUri" type= "hidden" value="${property.URI}" />
|
||||
// <input name="urlPattern" type="hidden" value="/propertyEdit" />
|
||||
// <input name="editform" type="hidden" value="admin/resourceDisplayVisibility.jsp"/>
|
||||
// <input type="submit" class="form-button" value="Set Property Display Visibility"/>
|
||||
// </form>
|
||||
// <form action="edit/editRequestDispatch.jsp" method="get">
|
||||
// <input name="home" type="hidden" value="${portalBean.portalId}" />
|
||||
// <input name="subjectUri" type="hidden" value="${property.URI}" />
|
||||
// <input name="urlPattern" type="hidden" value="/propertyEdit" />
|
||||
// <input name="editform" type="hidden" value="admin/resourceEditVisibility.jsp"/>
|
||||
// <input type="submit" class="form-button" value="Set Property Editing Visibility"/>
|
||||
// </form>
|
||||
|
||||
/* This form uses the unusual tactic of always configuring itself as if it were doing an update. */
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
|
||||
String urlPatternToReturnTo = (String)request.getAttribute("urlPatternToReturnTo");
|
||||
if (urlPatternToReturnTo==null || urlPatternToReturnTo.length()==0) {
|
||||
log.warn("urlPatternToReturnTo is null when starting resourceDisplayVisibility.jsp");
|
||||
System.out.println("urlPatternToReturnTo is null when starting resourceDisplayVisibility.jsp");
|
||||
} else {
|
||||
log.warn("urlPatternToReturnTo is "+urlPatternToReturnTo+" when starting resourceDisplayVisibility.jsp");
|
||||
System.out.println("urlPatternToReturnTo is "+urlPatternToReturnTo+" when starting resourceDisplayVisibility.jsp");
|
||||
}
|
||||
%>
|
||||
<c:choose>
|
||||
<c:when test="${!empty urlPatternToReturnTo}"><c:set var="urlPattern" value="${urlPatternToReturnTo}"/></c:when>
|
||||
<c:otherwise><c:set var="urlPattern" value="/entity" /></c:otherwise>
|
||||
</c:choose>
|
||||
<c:set var="roleOptions">
|
||||
["<%=BaseResourceBean.RoleLevel.PUBLIC.getURI()%>","<%=BaseResourceBean.RoleLevel.PUBLIC.getLabel() %>" ],
|
||||
["<%=BaseResourceBean.RoleLevel.SELF.getURI()%>","<%=BaseResourceBean.RoleLevel.SELF.getLabel() %>" ],
|
||||
["<%=BaseResourceBean.RoleLevel.EDITOR.getURI()%>","<%=BaseResourceBean.RoleLevel.EDITOR.getLabel() %>" ],
|
||||
["<%=BaseResourceBean.RoleLevel.CURATOR.getURI()%>","<%=BaseResourceBean.RoleLevel.CURATOR.getLabel() %>" ],
|
||||
["<%=BaseResourceBean.RoleLevel.DB_ADMIN.getURI()%>","<%=BaseResourceBean.RoleLevel.DB_ADMIN.getLabel() %>" ],
|
||||
["<%=BaseResourceBean.RoleLevel.NOBODY.getURI()%>","<%=BaseResourceBean.RoleLevel.NOBODY.getLabel() %>" ]
|
||||
</c:set>
|
||||
<v:jsonset var="displayRoleAssertions">
|
||||
@prefix vitro: <http://vitro.mannlib.connell.edu/ns/vitro/0.7#> .
|
||||
?subject vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayRole .
|
||||
</v:jsonset>
|
||||
<v:jsonset var="displayRoleExisting">
|
||||
prefix vitro: <http://vitro.mannlib.connell.edu/ns/vitro/0.7#>
|
||||
SELECT ?existingDisplayRole
|
||||
WHERE {
|
||||
?subject vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayRole .
|
||||
}
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "${urlPattern}",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ] ,
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "objectVar" , "http://example.org/valueJustToMakeItLookLikeAnUpdate" , "URI"],
|
||||
|
||||
"n3required" : [ "" ],
|
||||
"n3optional" : [ "" ],
|
||||
"newResources" : { },
|
||||
|
||||
"urisInScope" : { "displayRole" : "http://vitro.mannlib.cornell.edu/ns/vitro/role#public" },
|
||||
"literalsInScope" : { },
|
||||
|
||||
"urisOnForm" : ["displayRole"],
|
||||
"literalsOnForm" : [ ],
|
||||
"filesOnForm" : [ ],
|
||||
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { },
|
||||
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { "displayRole" : "${displayRoleExisting}" },
|
||||
"fields" : { "displayRole" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ ],
|
||||
"optionsType" : "LITERALS",
|
||||
"predicateUri" : "${predicateUriJson}",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"literalOptions" : [ ${roleOptions} ],
|
||||
"assertions" : ["${displayRoleAssertions}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<% /* now put edit configuration Json object into session */
|
||||
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
if (editConfig.getUrlPatternToReturnTo()==null) {
|
||||
System.out.println("urlPatternToReturnTo not initialized in resourceDisplayVisibility.jsp");
|
||||
log.debug("urlPatternToReturnTo not initialized");
|
||||
} else {
|
||||
System.out.println("urlPatternToReturnTo initialized to "+editConfig.getUrlPatternToReturnTo()+" in resourceDisplayVisibility.jsp");
|
||||
log.debug("urlPatternToReturnTo initialized to "+editConfig.getUrlPatternToReturnTo()+"\n");
|
||||
}
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
editConfig.prepareForObjPropUpdate( model );
|
||||
%>
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
||||
<h2>Set Display Visibility</h2>
|
||||
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
|
||||
<v:input type="select" id="displayRole" size="80" />
|
||||
<v:input type="submit" id="submit" value="submit" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
179
webapp/web/edit/forms/autoCompleteDatapropForm.jsp
Normal file
179
webapp/web/edit/forms/autoCompleteDatapropForm.jsp
Normal file
|
@ -0,0 +1,179 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
|
||||
|
||||
<%
|
||||
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.autoCompleteDatapropForm.jsp");
|
||||
log.debug("Starting autoCompleteDatapropForm.jsp");
|
||||
|
||||
String subjectUri = request.getParameter("subjectUri");
|
||||
String predicateUri = request.getParameter("predicateUri");
|
||||
|
||||
DataPropertyStatement dps = (DataPropertyStatement)request.getAttribute("dataprop");
|
||||
|
||||
String datapropKeyStr = request.getParameter("datapropKey");
|
||||
int dataHash=0;
|
||||
|
||||
DataProperty prop = (DataProperty)request.getAttribute("predicate");
|
||||
if( prop == null ) throw new Error("In autoCompleteDatapropForm.jsp, could not find predicate " + predicateUri);
|
||||
request.setAttribute("propertyName",prop.getPublicName());
|
||||
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
if( subject == null ) throw new Error("In autoCompleteDatapropForm.jsp, could not find subject " + subjectUri);
|
||||
request.setAttribute("subjectName",subject.getName());
|
||||
|
||||
String rangeDatatypeUri = prop.getRangeDatatypeURI();
|
||||
request.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
|
||||
|
||||
if( dps != null ){
|
||||
try {
|
||||
dataHash = Integer.parseInt(datapropKeyStr);
|
||||
log.debug("dataHash is " + dataHash);
|
||||
} catch (NumberFormatException ex) {
|
||||
log.debug("could not parse dataprop hash "+
|
||||
"but there was a dataproperty; hash: '"+datapropKeyStr+"'");
|
||||
}
|
||||
|
||||
String rangeDatatype = dps.getDatatypeURI();
|
||||
if( rangeDatatype == null ){
|
||||
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in autoCompleteDatapropForm.jsp");
|
||||
request.setAttribute("rangeDatatypeUriJson","");
|
||||
}else{
|
||||
log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in autoCompleteDatapropForm.jsp");
|
||||
request.setAttribute("rangeDatatypeUriJson",rangeDatatype);
|
||||
}
|
||||
String rangeLang = dps.getLanguage();
|
||||
if( rangeLang == null ) {
|
||||
log.debug("no language attribute on data property statement in autoCompleteDatapropForm.jsp");
|
||||
request.setAttribute("rangeLangJson","");
|
||||
}else{
|
||||
log.debug("language attribute of ["+rangeLang+"] on data property statement in autoCompleteDatapropForm.jsp");
|
||||
request.setAttribute("rangeLangJson", rangeLang);
|
||||
}
|
||||
} else {
|
||||
log.error("No incoming dataproperty statement attribute in autoCompleteDatapropForm.jsp");
|
||||
}
|
||||
%>
|
||||
<c:set var="dataLiteral" value="<%=prop.getLocalName()%>"/>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
?subject ?predicate ?${dataLiteral}.
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"datapropKey" : "<%=datapropKeyStr==null?"":datapropKeyStr%>",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : ["subject", "${subjectUriJson}" ],
|
||||
"predicate" : ["predicate", "${predicateUriJson}"],
|
||||
"object" : ["${dataLiteral}","","DATAPROPHASH"],
|
||||
|
||||
"n3required" : ["${n3ForEdit}"],
|
||||
"n3optional" : [ ],
|
||||
"newResources" : { },
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
"urisOnForm" : [ ],
|
||||
"literalsOnForm" : ["${dataLiteral}"],
|
||||
"filesOnForm" : [ ],
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { },
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"optionsForFields" : { },
|
||||
"fields" : { "${dataLiteral}" : {
|
||||
"newResource" : "false",
|
||||
"validators" : ["nonempty"],
|
||||
"optionsType" : "STRINGS_VIA_DATATYPE_PROPERTY",
|
||||
"literalOptions" : [],
|
||||
"predicateUri" : "${predicateUriJson}",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "${rangeDatatypeUriJson}" ,
|
||||
"rangeLang" : "${rangeLangJson}",
|
||||
"assertions" : ["${n3ForEdit}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<%
|
||||
if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson"));
|
||||
|
||||
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
|
||||
String formTitle =""; // dont add local page variables to the request
|
||||
String submitLabel ="";
|
||||
|
||||
if( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
editConfig.prepareForDataPropUpdate(model,dps);
|
||||
formTitle = "Change text for: <em>"+prop.getPublicName()+"</em>";
|
||||
submitLabel = "save change";
|
||||
} else {
|
||||
formTitle = "Add new entry for: <em>"+prop.getPublicName()+"</em>";
|
||||
submitLabel = "save entry";
|
||||
}
|
||||
%>
|
||||
|
||||
<jsp:include page="${preForm}">
|
||||
<jsp:param name="useTinyMCE" value="false"/>
|
||||
<jsp:param name="useAutoComplete" value="true"/>
|
||||
</jsp:include>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(this).load($(this).parent().children('a').attr('src')+" .editForm");
|
||||
|
||||
$(document).ready(function() {
|
||||
var key = $("input[name='editKey']").attr("value");
|
||||
$.getJSON("<c:url value="/dataservice"/>", {getN3EditOptionList:"1", field: "${dataLiteral}", editKey: key}, function(json){
|
||||
|
||||
$("select#${dataLiteral}").replaceWith("<input type='hidden' id='${dataLiteral}' name='${dataLiteral}' /><input type='text' id='${dataLiteral}-entry' name='${dataLiteral}-entry' />");
|
||||
|
||||
$("#${dataLiteral}-entry").autocomplete(json, {
|
||||
minChars: 1,
|
||||
width: 320,
|
||||
matchContains: true,
|
||||
mustMatch: 0,
|
||||
autoFill: false,
|
||||
// formatItem: function(row, i, max) {
|
||||
// return row[0];
|
||||
// },
|
||||
// formatMatch: function(row, i, max) {
|
||||
// return row[0];
|
||||
// },
|
||||
// formatResult: function(row) {
|
||||
// return row[0];
|
||||
// }
|
||||
|
||||
}).result(function(event, data, formatted) {
|
||||
$("input#${dataLiteral}-entry").attr("value", data[0]); // dump the string into the text box
|
||||
$("input#${dataLiteral}").attr("value", data[1]); // dump the uri into the hidden form input
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
</script>
|
||||
|
||||
<h2><%=formTitle%></h2>
|
||||
<form class="editForm" action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" >
|
||||
<c:if test="${!empty predicate.publicDescription}">
|
||||
<p class="propEntryHelpText">${predicate.publicDescription}</p>
|
||||
</c:if>
|
||||
<v:input type="select" id="${dataLiteral}"/>
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
<jsp:include page="${postForm}"/>
|
||||
|
||||
|
||||
|
193
webapp/web/edit/forms/autoCompleteObjPropForm.jsp
Normal file
193
webapp/web/edit/forms/autoCompleteObjPropForm.jsp
Normal file
|
@ -0,0 +1,193 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="org.apache.commons.logging.Log" %>
|
||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.autoCompleteObjPropForm.jsp");
|
||||
%>
|
||||
<%
|
||||
log.warn("Starting autoCompleteObjPropForm.jsp");
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
if( prop.getRangeVClassURI() == null ) {
|
||||
log.debug("Property has null for its range class URI");
|
||||
// If property has no explicit range, we will use e.g. owl:Thing.
|
||||
// Typically an allValuesFrom restriction will come into play later.
|
||||
VClass top = wdf.getVClassDao().getTopConcept();
|
||||
prop.setRangeVClassURI(top.getURI());
|
||||
log.debug("Using "+prop.getRangeVClassURI());
|
||||
}
|
||||
|
||||
VClass rangeClass = wdf.getVClassDao().getVClassByURI( prop.getRangeVClassURI());
|
||||
if( rangeClass == null ) log.debug("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
|
||||
%>
|
||||
|
||||
<v:jsonset var="queryForInverse" >
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
SELECT ?inverse_property
|
||||
WHERE {
|
||||
?inverse_property owl:inverseOf ?predicate
|
||||
}
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="objectVar" value="<%=prop.getLocalName()%>"/>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
?subject ?predicate ?${objectVar}.
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3Inverse" >
|
||||
?${objectVar} ?inverseProp ?subject.
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ] ,
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "${objectVar}" , "${objectUriJson}" , "URI"],
|
||||
|
||||
"n3required" : [ "${n3ForEdit}" ],
|
||||
"n3optional" : [ "${n3Inverse}" ],
|
||||
"newResources" : { },
|
||||
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
|
||||
"urisOnForm" : ["${objectVar}"],
|
||||
"literalsOnForm" : [ ],
|
||||
"filesOnForm" : [ ],
|
||||
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : {"inverseProp" : "${queryForInverse}" },
|
||||
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : { "${objectVar}" : {
|
||||
"newResource" : "false",
|
||||
"queryForExisting" : { },
|
||||
"validators" : [ ],
|
||||
"optionsType" : "INDIVIDUALS_VIA_OBJECT_PROPERTY",
|
||||
"subjectUri" : "${subjectUriJson}",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "${predicateUriJson}",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"literalOptions" : [ ] ,
|
||||
"assertions" : ["${n3ForEdit}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<% /* now put edit configuration Json object into session */
|
||||
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
String formTitle ="";
|
||||
String submitLabel ="";
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
|
||||
editConfig.prepareForObjPropUpdate( model );
|
||||
formTitle = "Change entry for: <em>"+prop.getDomainPublic()+"</em>";
|
||||
submitLabel = "save change";
|
||||
} else {
|
||||
editConfig.prepareForNonUpdate( model );
|
||||
if ( prop.getOfferCreateNewOption() ) {
|
||||
log.debug("property set to offer \"create new\" option; custom form: ["+prop.getCustomEntryForm()+"]");
|
||||
formTitle = "Select an existing "+rangeClass.getName()+" for "+subject.getName();
|
||||
submitLabel = "select existing";
|
||||
} else {
|
||||
formTitle = "Add an entry to: <em>"+prop.getDomainPublic()+"</em>";
|
||||
submitLabel = "save entry";
|
||||
}
|
||||
}
|
||||
%>
|
||||
<jsp:include page="${preForm}">
|
||||
<jsp:param name="useTinyMCE" value="false"/>
|
||||
<jsp:param name="useAutoComplete" value="true"/>
|
||||
</jsp:include>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(this).load($(this).parent().children('a').attr('src')+" .editForm");
|
||||
|
||||
$(document).ready(function() {
|
||||
var key = $("input[name='editKey']").attr("value");
|
||||
$.getJSON("<c:url value="/dataservice"/>", {getN3EditOptionList:"1", field: "${objectVar}", editKey: key}, function(json){
|
||||
|
||||
$("select#${objectVar}").replaceWith("<input type='hidden' id='${objectVar}' name='${objectVar}' /><input type='text' id='${objectVar}-entry' name='${objectVar}-entry' />");
|
||||
|
||||
$("#${objectVar}-entry").autocomplete(json, {
|
||||
minChars: 1,
|
||||
width: 320,
|
||||
matchContains: true,
|
||||
mustMatch: 1,
|
||||
autoFill: true,
|
||||
// formatItem: function(row, i, max) {
|
||||
// return row[0];
|
||||
// },
|
||||
// formatMatch: function(row, i, max) {
|
||||
// return row[0];
|
||||
// },
|
||||
// formatResult: function(row) {
|
||||
// return row[0];
|
||||
// }
|
||||
|
||||
}).result(function(event, data, formatted) {
|
||||
$("input#${objectVar}-entry").attr("value", data[0]); // dump the string into the text box
|
||||
$("input#${objectVar}").attr("value", data[1]); // dump the uri into the hidden form input
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
</script>
|
||||
|
||||
<h2><%=formTitle%></h2>
|
||||
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
|
||||
<c:if test="${predicate.offerCreateNewOption == true}">
|
||||
<c:url var="createNewUrl" value="/edit/editRequestDispatch.jsp">
|
||||
<c:param name="subjectUri" value="${param.subjectUri}"/>
|
||||
<c:param name="predicateUri" value="${param.predicateUri}"/>
|
||||
<c:param name="clearEditConfig" value="true"/>
|
||||
<c:param name="cmd" value="create"/>
|
||||
</c:url>
|
||||
</c:if>
|
||||
<c:if test="${!empty predicate.publicDescription}">
|
||||
<p>${predicate.publicDescription}</p>
|
||||
</c:if>
|
||||
<v:input type="select" id="${objectVar}" size="80" />
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
|
||||
<c:if test="${predicate.offerCreateNewOption == true}">
|
||||
<p>If you don't find the appropriate entry on the selection list,
|
||||
<button type="button" onclick="javascript:document.location.href='${createNewUrl}'">add a new item to this list</button>
|
||||
</p>
|
||||
</c:if>
|
||||
</form>
|
||||
|
||||
<c:if test="${!empty param.objectUri}" >
|
||||
<form class="deleteForm" action="editRequestDispatch.jsp" method="get">
|
||||
<label for="delete"><h3>Delete this entry?</h3></label>
|
||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
|
||||
<input type="hidden" name="cmd" value="delete"/>
|
||||
<v:input type="submit" id="delete" value="Delete" cancel="" />
|
||||
</form>
|
||||
</c:if>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
100
webapp/web/edit/forms/datapropStmtDelete.jsp
Normal file
100
webapp/web/edit/forms/datapropStmtDelete.jsp
Normal file
|
@ -0,0 +1,100 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
|
||||
<%@ 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.edit.n3editing.EditN3Utils"%>
|
||||
<%@ 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.RdfLiteralHash" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jstl/functions" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
|
||||
<%
|
||||
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.datapropStmtDelete");
|
||||
|
||||
if( session == null)
|
||||
throw new Error("need to have session");
|
||||
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {%>
|
||||
<c:redirect url="<%= Controllers.LOGIN %>" />
|
||||
<% }
|
||||
|
||||
String subjectUri = request.getParameter("subjectUri");
|
||||
String predicateUri = request.getParameter("predicateUri");
|
||||
String datapropKeyStr = request.getParameter("datapropKey");
|
||||
int dataHash = 0;
|
||||
if (datapropKeyStr!=null && datapropKeyStr.trim().length()>0) {
|
||||
try {
|
||||
dataHash = Integer.parseInt(datapropKeyStr);
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new JspException("Cannot decode incoming datapropKey String value "+datapropKeyStr+" as an integer hash in datapropStmtDelete.jsp");
|
||||
}
|
||||
}
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
String editorUri = EditN3Utils.getEditorUri(request,session,application);
|
||||
wdf = wdf.getUserAwareDaoFactory(editorUri);
|
||||
|
||||
DataProperty prop = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
|
||||
if( prop == null ) throw new Error("In datapropStmtDelete.jsp, could not find property " + predicateUri);
|
||||
request.setAttribute("propertyName",prop.getPublicName());
|
||||
|
||||
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
|
||||
if( subject == null ) throw new Error("could not find subject " + subjectUri);
|
||||
request.setAttribute("subjectName",subject.getName());
|
||||
|
||||
String dataValue=null;
|
||||
// DataPropertyStatement dps=EditConfiguration.findDataPropertyStatementViaHashcode(subject,predicateUri,dataHash);
|
||||
DataPropertyStatement dps= RdfLiteralHash.getDataPropertyStmtByHash(subject,dataHash);
|
||||
if( log.isDebugEnabled() ){
|
||||
log.debug("attempting to delete dataPropertyStatement: subjectURI <" + dps.getIndividualURI() +">");
|
||||
log.debug( "predicateURI <" + dps.getDatapropURI() + ">");
|
||||
log.debug( "literal \"" + dps.getData() + "\"" );
|
||||
log.debug( "lang @" + (dps.getLanguage() == null ? "null" : dps.getLanguage()));
|
||||
log.debug( "datatype ^^" + (dps.getDatatypeURI() == null ? "null" : dps.getDatatypeURI() ));
|
||||
}
|
||||
if( dps.getIndividualURI() == null || dps.getIndividualURI().trim().length() == 0){
|
||||
log.debug("adding missing subjectURI to DataPropertyStatement" );
|
||||
dps.setIndividualURI( subjectUri );
|
||||
}
|
||||
if( dps.getDatapropURI() == null || dps.getDatapropURI().trim().length() == 0){
|
||||
log.debug("adding missing datapropUri to DataPropertyStatement");
|
||||
dps.setDatapropURI( predicateUri );
|
||||
}
|
||||
|
||||
if (dps!=null) {
|
||||
dataValue = dps.getData().trim();
|
||||
if( request.getParameter("y") != null ) { //do the delete
|
||||
wdf.getDataPropertyStatementDao().deleteDataPropertyStatement(dps);%>
|
||||
|
||||
<%-- grab the predicate URI and trim it down to get the Local Name so we can send the user back to the appropriate property --%>
|
||||
<c:set var="predicateUri" value="${param.predicateUri}" />
|
||||
<c:set var="localName" value="${fn:substringAfter(predicateUri, '#')}" />
|
||||
<c:url var="redirectUrl" value="../entity">
|
||||
<c:param name="uri" value="${param.subjectUri}"/>
|
||||
</c:url>
|
||||
<c:redirect url="${redirectUrl}${'#'}${localName}"/>
|
||||
|
||||
<% } else { %>
|
||||
<jsp:include page="${preForm}"/>
|
||||
<form action="editDatapropStmtRequestDispatch.jsp" method="get">
|
||||
<label for="submit"><h2>Are you sure you want to delete the following entry from <em>${propertyName}</em>?</h2></label>
|
||||
<div class="toBeDeleted dataProp"><%=dataValue%></div>
|
||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||
<input type="hidden" name="datapropKey" value="${param.datapropKey}"/>
|
||||
<input type="hidden" name="y" value="1"/>
|
||||
<input type="hidden" name="cmd" value="delete"/>
|
||||
<v:input type="submit" id="submit" value="Delete" cancel="${param.subjectUri}" />
|
||||
</form>
|
||||
<jsp:include page="${postForm}"/>
|
||||
<% }
|
||||
} else {
|
||||
throw new Error("In datapropStmtDelete.jsp, no match via hashcode to existing datatype property "+predicateUri+" for subject "+subject.getName()+"\n");
|
||||
}%>
|
255
webapp/web/edit/forms/defaultAddMissingIndividualForm.jsp
Normal file
255
webapp/web/edit/forms/defaultAddMissingIndividualForm.jsp
Normal file
|
@ -0,0 +1,255 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ 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.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.ModelChangePreprocessor"%>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.DefaultAddMissingIndividualFormModelPreprocessor"%>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena"%>
|
||||
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
|
||||
if (prop == null) throw new Error("no object property specified via incoming predicate attribute in defaultAddMissingIndividualForm.jsp");
|
||||
String propDomainPublic = (prop.getDomainPublic() == null) ? "affiliation" : prop.getDomainPublic();
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
if( prop.getRangeVClassURI() == null ) {
|
||||
// If property has no explicit range, we will use e.g. owl:Thing.
|
||||
// Typically an allValuesFrom restriction will come into play later.
|
||||
VClass top = wdf.getVClassDao().getTopConcept();
|
||||
prop.setRangeVClassURI(top.getURI());
|
||||
}
|
||||
|
||||
String objectUri = (String)request.getAttribute("objectUri");
|
||||
String predicateUri = (String)request.getAttribute("predicateUri");
|
||||
|
||||
boolean isForwardToCreateNew = request.getAttribute("isForwardToCreateNew") != null &&
|
||||
(Boolean)request.getAttribute("isForwardToCreateNew") == true;
|
||||
|
||||
// If this request is the first forward to this form we need to create a new
|
||||
// edit key because the request will be coming from a defaultObjPropForm and
|
||||
// will have an edit key that will be reused by the EditConfiguration that
|
||||
// is being created below. This also preserves back button functionality to
|
||||
// the form this request is coming from. If the edit key was not cleared
|
||||
// the new editConfig below would overwrite the previous form's editConfig
|
||||
// in the Session.
|
||||
if( isForwardToCreateNew )
|
||||
request.setAttribute("editKey", EditConfiguration.newEditKey(session));
|
||||
|
||||
//If a objectProperty is both provideSelect and offerCreateNewOption
|
||||
// then when the user gos to a default ObjectProperty edit for an existing
|
||||
// object property statement then the user can create a new Individual,
|
||||
// and replace the object in the existing objectPropertyStatement with
|
||||
// this new individual.
|
||||
boolean isReplaceWithNew = request.getAttribute("isReplaceWithNew") != null &&
|
||||
(Boolean)request.getAttribute("isReplaceWithNew") == 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 = request.getAttribute("isForwardToCreateButEdit") != null
|
||||
&& (Boolean)request.getAttribute("isForwardToCreateButEdit") == true;
|
||||
|
||||
vreq.setAttribute("defaultNamespace",wdf.getDefaultNamespace());
|
||||
|
||||
StringBuffer n3AssertedTypesUnescapedBuffer = new StringBuffer();
|
||||
|
||||
// TODO: redo to query restrictions directly. getVClassesForProperty returns the subclasses, which we don't want.
|
||||
|
||||
//for ( VClass vclass : assertionsWdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(),prop.getURI()) ) {
|
||||
// if (vclass.getURI()!=null) {
|
||||
// n3AssertedTypesUnescapedBuffer.append("?newIndividual ").append(" rdf:type <")
|
||||
// .append(vclass.getURI()).append("> .\n");
|
||||
// }
|
||||
//}
|
||||
vreq.setAttribute("n3AssertedTypesUnescaped",n3AssertedTypesUnescapedBuffer.toString());
|
||||
|
||||
// if we don't check it into the portal, we won't be able to see it
|
||||
vreq.setAttribute("portalUri", vreq.getPortal().getTypeUri());
|
||||
|
||||
String flagURI = null;
|
||||
if (vreq.getAppBean().isFlag1Active()) {
|
||||
flagURI = VitroVocabulary.vitroURI+"Flag1Value"+vreq.getPortal().getPortalId()+"Thing";
|
||||
} else {
|
||||
flagURI = wdf.getVClassDao().getTopConcept().getURI(); // fall back to owl:Thing if not portal filtering
|
||||
}
|
||||
vreq.setAttribute("flagURI",flagURI);
|
||||
|
||||
VClass rangeClass = null;
|
||||
String typeOfNew = (String)vreq.getAttribute("typeOfNew");
|
||||
if(typeOfNew != null )
|
||||
rangeClass = wdf.getVClassDao().getVClassByURI( typeOfNew );
|
||||
if( rangeClass == null ){
|
||||
rangeClass = wdf.getVClassDao().getVClassByURI(prop.getRangeVClassURI());
|
||||
if( rangeClass == null ) throw new Error ("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
|
||||
}
|
||||
//vreq.setAttribute("rangeClassLocalName",rangeClass.getLocalName());
|
||||
//vreq.setAttribute("rangeClassNamespace",rangeClass.getNamespace());
|
||||
vreq.setAttribute("rangeClassUri",rangeClass.getURI());
|
||||
|
||||
//todo: set additional ranges using allValuesFrom.
|
||||
|
||||
//vreq.setAttribute("curatorReviewUri","http://vivo.library.cornell.edu/ns/0.1#CuratorReview");
|
||||
%>
|
||||
|
||||
<v:jsonset var="queryForInverse" >
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
SELECT ?inverse_property
|
||||
WHERE {
|
||||
?inverse_property owl:inverseOf ?predicate
|
||||
}
|
||||
</v:jsonset>
|
||||
|
||||
<%-- Enter a SPARQL query for each field, by convention concatenating the field id with "Existing"
|
||||
to convey that the expression is used to retrieve any existing value for the field in an existing individual.
|
||||
Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below
|
||||
and in the literalsOnForm --%>
|
||||
<v:jsonset var="nameExisting" >
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
SELECT ?existingName
|
||||
WHERE { ?newIndividual rdfs:label ?existingName }
|
||||
</v:jsonset>
|
||||
|
||||
<%-- Pair the "existing" query with the skeleton of what will be asserted for a new statement involving this field.
|
||||
the actual assertion inserted in the model will be created via string substitution into the ? variables.
|
||||
NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%>
|
||||
<v:jsonset var="n3ForName" >
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
?newIndividual rdfs:label ?name .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3ForRelation" >
|
||||
?subject ?predicate ?newIndividual .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3ForType" >
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
?newIndividual rdf:type <${rangeClassUri}> .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3ForFlag" >
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
?newIndividual rdf:type <${flagURI}> .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- using v:jsonset here so everything goes through the same JSON escaping --%>
|
||||
<v:jsonset var="n3AssertedTypes">
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
${n3AssertedTypesUnescaped}
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3Inverse" >
|
||||
?newIndividual ?inverseProp ?subject .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- note that it's safer to have multiple distinct optional blocks so that a failure in one
|
||||
will not prevent correct sections from being inserted --%>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ],
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "newIndividual", "${objectUriJson}", "URI" ],
|
||||
|
||||
"n3required" : [ "${n3ForName}" , "${n3ForRelation}", "${n3ForType}"],
|
||||
"n3optional" : [ "${n3Inverse}", "${n3AssertedTypes}", "${n3ForFlag}" ],
|
||||
"newResources" : {
|
||||
"newIndividual" : "${defaultNamespace}individual"
|
||||
},
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
"urisOnForm" : [ ],
|
||||
"literalsOnForm" : [ "name" ],
|
||||
"filesOnForm" : [ ],
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { "inverseProp" : "${queryForInverse}" },
|
||||
"sparqlForExistingLiterals" : {
|
||||
"name" : "${nameExisting}"
|
||||
},
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : {
|
||||
"name" : {
|
||||
"newResource" : "false",
|
||||
"validators" : ["nonempty"],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${n3ForName}" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
<%
|
||||
EditConfiguration editConfig = null;
|
||||
if( ! isForwardToCreateNew )
|
||||
editConfig = EditConfiguration.getConfigFromSession(session,request);
|
||||
//else
|
||||
// don't want to get the editConfig because it was for the defaultObjPropForm
|
||||
|
||||
if( editConfig == null ){
|
||||
editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
}
|
||||
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
|
||||
if( isReplaceWithNew){
|
||||
// this is very specialized for the defaultAddMissingIndividual.jsp
|
||||
// to support objPropStmt edits where the user wants to
|
||||
// create a new Individual. Here we trick the processRdfForm2 into
|
||||
// creating a new Individual and use the preprocessor to do the
|
||||
// removal of the old objPropStmt
|
||||
editConfig.addModelChangePreprocessor(
|
||||
new DefaultAddMissingIndividualFormModelPreprocessor(
|
||||
subject.getURI(),predicateUri ,objectUri ) );
|
||||
editConfig.setObject(null);
|
||||
editConfig.prepareForNonUpdate(model);
|
||||
}else if ( isForwardToCreateButEdit) {
|
||||
editConfig.prepareForObjPropUpdate(model);
|
||||
}else if(request.getAttribute("object") != null ){
|
||||
editConfig.prepareForObjPropUpdate(model);
|
||||
} else{
|
||||
editConfig.prepareForNonUpdate(model);
|
||||
}
|
||||
|
||||
String submitButtonLabel="";
|
||||
/* title is used by pre and post form fragments */
|
||||
if (objectUri != null) {
|
||||
request.setAttribute("title", "Edit \""+propDomainPublic+"\" entry for " + subject.getName());
|
||||
submitButtonLabel = "Save changes";
|
||||
} else {
|
||||
request.setAttribute("title","Create a new \""+propDomainPublic+"\" entry for " + subject.getName());
|
||||
submitButtonLabel = "Create new \""+propDomainPublic+"\" entry";
|
||||
}
|
||||
|
||||
%>
|
||||
|
||||
<jsp:include page="${preForm}">
|
||||
<jsp:param name="useTinyMCE" value="false"/>
|
||||
<jsp:param name="useAutoComplete" value="false"/>
|
||||
</jsp:include>
|
||||
|
||||
<h2>${title}</h2>
|
||||
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" ><br/>
|
||||
<v:input type="text" label="name (required)" id="name" size="30"/><br/>
|
||||
<v:input type="submit" id="submit" value="<%=submitButtonLabel%>" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
176
webapp/web/edit/forms/defaultDatapropForm.jsp
Normal file
176
webapp/web/edit/forms/defaultDatapropForm.jsp
Normal file
|
@ -0,0 +1,176 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ 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.controller.VitroRequest"%>
|
||||
<%@ page import="java.util.HashMap"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
|
||||
|
||||
<%! private static HashMap<String,String> defaultsForXSDtypes ;
|
||||
static {
|
||||
defaultsForXSDtypes = new HashMap<String,String>();
|
||||
//defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","2001-01-01T12:00:00");
|
||||
defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","#Unparseable datetime defaults to now");
|
||||
}
|
||||
%>
|
||||
<%
|
||||
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.defaultDatapropForm.jsp");
|
||||
log.debug("Starting defaultDatapropForm.jsp");
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
|
||||
String subjectUri = vreq.getParameter("subjectUri");
|
||||
String predicateUri = vreq.getParameter("predicateUri");
|
||||
|
||||
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
||||
|
||||
String datapropKeyStr = vreq.getParameter("datapropKey");
|
||||
int dataHash=0;
|
||||
|
||||
DataProperty prop = (DataProperty)vreq.getAttribute("predicate");
|
||||
if( prop == null ) throw new Error("In defaultDatapropForm.jsp, could not find predicate " + predicateUri);
|
||||
vreq.setAttribute("propertyName",prop.getPublicName());
|
||||
|
||||
Individual subject = (Individual)vreq.getAttribute("subject");
|
||||
if( subject == null ) throw new Error("In defaultDatapropForm.jsp, could not find subject " + subjectUri);
|
||||
vreq.setAttribute("subjectName",subject.getName());
|
||||
|
||||
String rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, prop);
|
||||
//String rangeDatatypeUri = prop.getRangeDatatypeURI();
|
||||
vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
|
||||
|
||||
if( dps != null ){
|
||||
try {
|
||||
dataHash = Integer.parseInt(datapropKeyStr);
|
||||
log.debug("dataHash is " + dataHash);
|
||||
} catch (NumberFormatException ex) {
|
||||
log.debug("could not parse dataprop hash "+
|
||||
"but there was a dataproperty; hash: '"+datapropKeyStr+"'");
|
||||
}
|
||||
|
||||
String rangeDatatype = dps.getDatatypeURI();
|
||||
if( rangeDatatype == null ){
|
||||
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in defaultDatapropForm.jsp");
|
||||
vreq.setAttribute("rangeDatatypeUriJson","");
|
||||
} else {
|
||||
log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in defaultDatapropForm.jsp");
|
||||
vreq.setAttribute("rangeDatatypeUriJson",rangeDatatype);
|
||||
}
|
||||
String rangeLang = dps.getLanguage();
|
||||
if( rangeLang == null ) {
|
||||
log.debug("no language attribute on data property statement in defaultDatapropForm.jsp");
|
||||
vreq.setAttribute("rangeLangJson","");
|
||||
}else{
|
||||
log.debug("language attribute of ["+rangeLang+"] on data property statement in defaultDatapropForm.jsp");
|
||||
vreq.setAttribute("rangeLangJson", rangeLang);
|
||||
}
|
||||
} else {
|
||||
log.debug("No incoming dataproperty statement attribute for property "+prop.getPublicName()+", adding a new statement");
|
||||
if(rangeDatatypeUri != null && rangeDatatypeUri.length() > 0) {
|
||||
String defaultVal = defaultsForXSDtypes.get(rangeDatatypeUri);
|
||||
if( defaultVal == null )
|
||||
vreq.setAttribute("rangeDefaultJson", "");
|
||||
else
|
||||
vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' );
|
||||
}
|
||||
}
|
||||
|
||||
%>
|
||||
<c:set var="localName" value="<%=prop.getLocalName()%>"/>
|
||||
<c:set var="dataLiteral" value="${localName}Edited"/>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
?subject ?predicate ?${dataLiteral}.
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"datapropKey" : "<%=datapropKeyStr==null?"":datapropKeyStr%>",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : ["subject", "${subjectUriJson}" ],
|
||||
"predicate" : ["predicate", "${predicateUriJson}"],
|
||||
"object" : ["${dataLiteral}","","DATAPROPHASH"],
|
||||
|
||||
"n3required" : ["${n3ForEdit}"],
|
||||
"n3optional" : [ ],
|
||||
"newResources" : { },
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
"urisOnForm" : [ ],
|
||||
"literalsOnForm" : ["${dataLiteral}"],
|
||||
"filesOnForm" : [ ],
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { },
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"optionsForFields" : { },
|
||||
"fields" : { "${dataLiteral}" : {
|
||||
"newResource" : "false",
|
||||
"validators" : ["datatype:${rangeDatatypeUriJson}"],
|
||||
"optionsType" : "LITERALS",
|
||||
"literalOptions" : [ ${rangeDefaultJson} ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "${rangeDatatypeUriJson}" ,
|
||||
"rangeLang" : "${rangeLangJson}",
|
||||
"assertions" : ["${n3ForEdit}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<%
|
||||
if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson"));
|
||||
|
||||
EditConfiguration editConfig = new EditConfiguration((String)vreq.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
|
||||
String formTitle =""; // don't add local page variables to the request
|
||||
String submitLabel ="";
|
||||
|
||||
if( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
editConfig.prepareForDataPropUpdate(model,dps);
|
||||
formTitle = "Change text for: <em>"+prop.getPublicName()+"</em>";
|
||||
submitLabel = "save change";
|
||||
} else {
|
||||
formTitle ="Add new entry for: <em>"+prop.getPublicName()+"</em>";
|
||||
submitLabel ="save entry";
|
||||
}
|
||||
%>
|
||||
|
||||
<%--the following parameters configure the tinymce textarea --%>
|
||||
<jsp:include page="${preForm}">
|
||||
<jsp:param name="useTinyMCE" value="true"/>
|
||||
</jsp:include>
|
||||
|
||||
<h2><%=formTitle%></h2>
|
||||
<form class="editForm" action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" method="post" > <%-- see VITRO-435 Jira issue: need POST, not GET --%>
|
||||
<c:if test="${!empty predicate.publicDescription}">
|
||||
<label for="${dataLiteral}"><p class="propEntryHelpText">${predicate.publicDescription}</p></label>
|
||||
</c:if>
|
||||
<v:input type="textarea" id="${dataLiteral}" rows="2"/>
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<c:if test="${ (!empty param.datapropKey) && (empty param.deleteProhibited) }">
|
||||
<form class="deleteForm" action="editDatapropStmtRequestDispatch.jsp" method="post">
|
||||
<label for="delete"><h3>Delete this entry?</h3></label>
|
||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||
<input type="hidden" name="datapropKey" value="${param.datapropKey}"/>
|
||||
<input type="hidden" name="cmd" value="delete"/>
|
||||
<v:input type="submit" id="delete" value="Delete" cancel="" />
|
||||
</form>
|
||||
</c:if>
|
||||
<jsp:include page="${postForm}"/>
|
||||
|
||||
|
||||
|
167
webapp/web/edit/forms/defaultLinkForm.jsp
Normal file
167
webapp/web/edit/forms/defaultLinkForm.jsp
Normal file
|
@ -0,0 +1,167 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ 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.beans.DataProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ page import="org.apache.commons.logging.Log" %>
|
||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.defaultLinkForm.jsp");
|
||||
%>
|
||||
<%-- Enter here any class names to be used for constructing INDIVIDUALS_VIA_VCLASS pick lists
|
||||
These are then referenced in the field's ObjectClassUri but not elsewhere.
|
||||
NOTE that this class may not exist in the model, in which the only choice of type
|
||||
that will show up is "web page", which will insert no new statements and just create
|
||||
links of type vitro:Link --%>
|
||||
|
||||
<%-- Then enter a SPARQL query for each field, by convention concatenating the field id with "Existing"
|
||||
to convey that the expression is used to retrieve any existing value for the field in an existing individual.
|
||||
Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below
|
||||
and in the literalsOnForm --%>
|
||||
<v:jsonset var="urlExisting" >
|
||||
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
|
||||
SELECT ?urlExisting
|
||||
WHERE { ?link vitro:linkURL ?urlExisting }
|
||||
</v:jsonset>
|
||||
<%-- Pair the "existing" query with the skeleton of what will be asserted for a new statement involving this field.
|
||||
The actual assertion inserted in the model will be created via string substitution into the ? variables.
|
||||
NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%>
|
||||
<v:jsonset var="urlAssertion" >
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
?link vitro:linkURL ?url .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="anchorExisting" >
|
||||
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
|
||||
SELECT ?anchorExisting
|
||||
WHERE { ?link vitro:linkAnchor ?anchorExisting }
|
||||
</v:jsonset>
|
||||
<v:jsonset var="anchorAssertion" >
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
?link vitro:linkAnchor ?anchor .
|
||||
</v:jsonset>
|
||||
|
||||
<%-- When not retrieving a literal via a datatype property, put the SPARQL statement into
|
||||
the SparqlForExistingUris --%>
|
||||
|
||||
<v:jsonset var="n3ForEdit">
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
|
||||
?subject vitro:additionalLink ?link .
|
||||
|
||||
?link rdf:type vitro:Link .
|
||||
|
||||
?link
|
||||
vitro:linkURL ?url ;
|
||||
vitro:linkAnchor ?anchor .
|
||||
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3Optional">
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
|
||||
?link rdf:type ?type .
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : ["subject", "${subjectUriJson}" ],
|
||||
"predicate" : ["predicate", "${predicateUriJson}" ],
|
||||
"object" : ["link", "${objectUriJson}", "URI" ],
|
||||
|
||||
"n3required" : [ "${n3ForEdit}" ],
|
||||
"n3optional" : [ "${n3Optional}" ],
|
||||
"newResources" : { "link" : "http://vivo.library.cornell.edu/ns/0.1#individual" },
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
"urisOnForm" : [ ],
|
||||
"literalsOnForm" : [ "url", "anchor" ],
|
||||
"filesOnForm" : [ ],
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { },
|
||||
"sparqlForExistingLiterals" : {
|
||||
"url" : "${urlExisting}",
|
||||
"anchor" : "${anchorExisting}"
|
||||
},
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : {
|
||||
"url" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${urlAssertion}" ]
|
||||
},
|
||||
"anchor" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${anchorAssertion}" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
<%
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
|
||||
if( editConfig == null ){
|
||||
editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
}
|
||||
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
String objectUri = (String)request.getAttribute("objectUri");
|
||||
if( objectUri != null ){
|
||||
editConfig.prepareForObjPropUpdate(model);
|
||||
}else{
|
||||
editConfig.prepareForNonUpdate(model);
|
||||
}
|
||||
|
||||
/* get some data to make the form more useful */
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
|
||||
String submitLabel=""; // don't put local variables into the request
|
||||
/* title is used by pre and post form fragments */
|
||||
if (objectUri != null) {
|
||||
request.setAttribute("title", "Edit link for " + subject.getName());
|
||||
submitLabel = "Save changes";
|
||||
} else {
|
||||
request.setAttribute("title","Create a new link for " + subject.getName());
|
||||
submitLabel = "Create new link";
|
||||
}
|
||||
|
||||
%>
|
||||
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
||||
<h2>${title}</h2>
|
||||
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
|
||||
<v:input type="text" label="URL" id="url" size="70"/>
|
||||
<v:input type="text" label="label" id="anchor" size="60"/>
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
188
webapp/web/edit/forms/defaultObjPropForm.jsp
Normal file
188
webapp/web/edit/forms/defaultObjPropForm.jsp
Normal file
|
@ -0,0 +1,188 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="org.apache.commons.logging.Log" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.defaultObjPropForm.jsp");
|
||||
%>
|
||||
<%
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
if( prop.getRangeVClassURI() == null ) {
|
||||
log.debug("Property has null for its range class URI");
|
||||
// If property has no explicit range, we will use e.g. owl:Thing.
|
||||
// Typically an allValuesFrom restriction will come into play later.
|
||||
VClass top = wdf.getVClassDao().getTopConcept();
|
||||
prop.setRangeVClassURI(top.getURI());
|
||||
log.debug("Using "+prop.getRangeVClassURI());
|
||||
}
|
||||
|
||||
VClass rangeClass = wdf.getVClassDao().getVClassByURI( prop.getRangeVClassURI());
|
||||
if( rangeClass == null ) log.debug("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
|
||||
%>
|
||||
|
||||
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator"%>
|
||||
<%@page import="java.util.Map"%><v:jsonset var="queryForInverse" >
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
SELECT ?inverse_property
|
||||
WHERE {
|
||||
?inverse_property owl:inverseOf ?predicate
|
||||
}
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
?subject ?predicate ?objectVar.
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3Inverse" >
|
||||
?objectVar ?inverseProp ?subject.
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ] ,
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "objectVar" , "${objectUriJson}" , "URI"],
|
||||
|
||||
"n3required" : [ "${n3ForEdit}" ],
|
||||
"n3optional" : [ "${n3Inverse}" ],
|
||||
"newResources" : { },
|
||||
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
|
||||
"urisOnForm" : ["objectVar"],
|
||||
"literalsOnForm" : [ ],
|
||||
"filesOnForm" : [ ],
|
||||
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : {"inverseProp" : "${queryForInverse}" },
|
||||
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : { "objectVar" : {
|
||||
"newResource" : "false",
|
||||
"queryForExisting" : { },
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "INDIVIDUALS_VIA_OBJECT_PROPERTY",
|
||||
"subjectUri" : "${subjectUriJson}",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "${predicateUriJson}",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"literalOptions" : [ ] ,
|
||||
"assertions" : ["${n3ForEdit}", "${n3Inverse}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<% /* now put edit configuration Json object into session */
|
||||
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
String formTitle ="";
|
||||
String submitLabel ="";
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
|
||||
editConfig.prepareForObjPropUpdate( model );
|
||||
formTitle = "Change entry for: <em>"+prop.getDomainPublic()+"</em>";
|
||||
submitLabel = "save change";
|
||||
} else {
|
||||
editConfig.prepareForNonUpdate( model );
|
||||
if ( prop.getOfferCreateNewOption() ) {
|
||||
log.debug("property set to offer \"create new\" option; custom form: ["+prop.getCustomEntryForm()+"]");
|
||||
formTitle = "Select an existing "+rangeClass.getName()+" for "+subject.getName();
|
||||
submitLabel = "select existing";
|
||||
} else {
|
||||
formTitle = "Add an entry to: <em>"+prop.getDomainPublic()+"</em>";
|
||||
submitLabel = "save entry";
|
||||
}
|
||||
}
|
||||
|
||||
if( prop.getSelectFromExisting() ){
|
||||
Map<String,String> rangeOptions = SelectListGenerator.getOptions(editConfig, "objectVar" , wdf);
|
||||
if( rangeOptions != null && rangeOptions.size() > 0 )
|
||||
request.setAttribute("rangeOptionsExist", true);
|
||||
else
|
||||
request.setAttribute("rangeOptionsExist",false);
|
||||
}
|
||||
%>
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
||||
<h2><%=formTitle%></h2>
|
||||
|
||||
<c:if test="${requestScope.predicate.selectFromExisting == true }">
|
||||
<c:if test="${requestScope.rangeOptionsExist == true }">
|
||||
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
|
||||
<c:if test="${!empty predicate.publicDescription}">
|
||||
<p>${predicate.publicDescription}</p>
|
||||
</c:if>
|
||||
<v:input type="select" id="objectVar" size="80" />
|
||||
<div style="margin-top: 1em">
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
|
||||
</div>
|
||||
</form>
|
||||
</c:if>
|
||||
<c:if test="${requestScope.rangeOptionsExist == false }">
|
||||
<p>There are no entries in the system to select from.</p>
|
||||
</c:if>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${requestScope.predicate.offerCreateNewOption == true}">
|
||||
<c:if test="${requestScope.rangeOptionsExist == true }">
|
||||
<p>If you don't find the appropriate entry on the selection list:</p>
|
||||
</c:if>
|
||||
<c:if test="${requestScope.rangeOptionsExist == false }">
|
||||
<p style="margin-top: 5em">Please create a new entry.</p>
|
||||
</c:if>
|
||||
<c:url var="createNewUrl" value="/edit/editRequestDispatch.jsp"/>
|
||||
<form class="editForm" action="${createNewUrl}">
|
||||
<input type="hidden" value="${param.subjectUri}" name="subjectUri"/>
|
||||
<input type="hidden" value="${param.predicateUri}" name="predicateUri"/>
|
||||
<input type="hidden" value="${param.objectUri}" name="objectUri"/>
|
||||
<input type="hidden" value="create" name="cmd"/>
|
||||
<v:input type="typesForCreateNew" id="typeOfNew" />
|
||||
<v:input type="submit" id="submit" value="add a new item to this list"/>
|
||||
</form>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${(requestScope.predicate.offerCreateNewOption == false) && (requestScope.predicate.selectFromExisting == false)}">
|
||||
<p>This property is currently configured to prohibit editing. </p>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${ (!empty param.objectUri) && (empty param.deleteProhibited) }" >
|
||||
<form class="deleteForm" action="editRequestDispatch.jsp" method="get">
|
||||
<label for="delete"><h3>Delete this entry?</h3></label>
|
||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
|
||||
<input type="hidden" name="cmd" value="delete"/>
|
||||
<c:if test="${(requestScope.predicate.offerCreateNewOption == false) && (requestScope.predicate.selectFromExisting == false)}">
|
||||
<v:input type="submit" id="delete" value="Delete" cancel="cancel" />
|
||||
</c:if>
|
||||
<c:if test="${(requestScope.predicate.offerCreateNewOption == true) || (requestScope.predicate.selectFromExisting == true)}">
|
||||
<v:input type="submit" id="delete" value="Delete" cancel="" />
|
||||
</c:if>
|
||||
</form>
|
||||
</c:if>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
153
webapp/web/edit/forms/propDelete.jsp
Normal file
153
webapp/web/edit/forms/propDelete.jsp
Normal file
|
@ -0,0 +1,153 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%><%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jstl/functions" %>
|
||||
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement"%>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty"%>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Link" %>
|
||||
<%@ 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.dao.VitroVocabulary" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.LinksDao" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ 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.forms.propDelete.jsp");
|
||||
|
||||
public WebappDaoFactory getUnfilteredDaoFactory() {
|
||||
return (WebappDaoFactory) getServletContext().getAttribute("webappDaoFactory");
|
||||
}
|
||||
%>
|
||||
|
||||
<%-- grab the predicate URI and trim it down to get the Local Name so we can send the user back to the appropriate property --%>
|
||||
<c:set var="predicateUri" value="${param.predicateUri}" />
|
||||
<c:set var="localName" value="${fn:substringAfter(predicateUri, '#')}" />
|
||||
<c:url var="redirectUrl" value="../entity">
|
||||
<c:param name="uri" value="${param.subjectUri}"/>
|
||||
</c:url>
|
||||
|
||||
<%
|
||||
if( session == null) {
|
||||
throw new Error("need to have session");
|
||||
}
|
||||
boolean selfEditing = VitroRequestPrep.isSelfEditing(request);
|
||||
if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {%>
|
||||
<c:redirect url="<%= Controllers.LOGIN %>" />
|
||||
<% }
|
||||
|
||||
String subjectUri = request.getParameter("subjectUri");
|
||||
String predicateUri = request.getParameter("predicateUri");
|
||||
String objectUri = request.getParameter("objectUri");
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
if( wdf == null ) {
|
||||
throw new Error("could not get a WebappDaoFactory");
|
||||
}
|
||||
ObjectProperty prop = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||
if( prop == null ) {
|
||||
throw new Error("In propDelete.jsp, could not find property " + predicateUri);
|
||||
}
|
||||
request.setAttribute("propertyName",prop.getDomainPublic());
|
||||
|
||||
//do the delete
|
||||
if( request.getParameter("y") != null ) {
|
||||
|
||||
String editorUri = EditN3Utils.getEditorUri(request,session,application);
|
||||
wdf = wdf.getUserAwareDaoFactory(editorUri);
|
||||
|
||||
if (prop.getForceStubObjectDeletion()) {
|
||||
Individual object = (Individual)request.getAttribute("object");
|
||||
if (object==null) {
|
||||
object = getUnfilteredDaoFactory().getIndividualDao().getIndividualByURI(objectUri);
|
||||
}
|
||||
if( object != null ) {
|
||||
log.warn("Deleting individual "+object.getName()+" since property has been set to force range object deletion");
|
||||
wdf.getIndividualDao().deleteIndividual(object);
|
||||
} else {
|
||||
throw new Error("Could not find object as request attribute or in model: '" + objectUri + "'");
|
||||
}
|
||||
}
|
||||
wdf.getPropertyInstanceDao().deleteObjectPropertyStatement(subjectUri,predicateUri,objectUri); %>
|
||||
<c:redirect url="${redirectUrl}${'#'}${localName}"/>
|
||||
<% }
|
||||
|
||||
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
|
||||
if( subject == null ) throw new Error("could not find subject " + subjectUri);
|
||||
request.setAttribute("subjectName",subject.getName());
|
||||
|
||||
boolean foundClass = false;
|
||||
String customShortView = null;
|
||||
String shortViewPrefix = "/templates/entity/";
|
||||
Individual object = getUnfilteredDaoFactory().getIndividualDao().getIndividualByURI(objectUri);
|
||||
if( object == null ) {
|
||||
log.warn("Could not find object individual "+objectUri+" via wdf.getIndividualDao().getIndividualByURI(objectUri)");
|
||||
request.setAttribute("objectName","(name unspecified)");
|
||||
} else {
|
||||
for (VClass clas : object.getVClasses(true)) { // direct VClasses, not inferred, and not including Vitro namespace
|
||||
request.setAttribute("rangeClassName", clas.getName());
|
||||
foundClass = true;
|
||||
customShortView = clas.getCustomShortView();
|
||||
if (customShortView != null && customShortView.trim().length()>0) {
|
||||
log.debug("setting object name from VClass custom short view");
|
||||
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
|
||||
request.setAttribute("individual",object);
|
||||
} else {
|
||||
log.debug("No custom short view for class, so setting object name from object individual name");
|
||||
request.setAttribute("objectName",object.getName());
|
||||
}
|
||||
}
|
||||
if (!foundClass) {
|
||||
VClass clas = prop.getRangeVClass();
|
||||
if (clas != null) {
|
||||
customShortView = clas.getCustomShortView();
|
||||
if (customShortView != null && customShortView.trim().length()>0) {
|
||||
log.warn("setting object name from VClass custom short view \""+customShortView.trim()+"\"");
|
||||
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
|
||||
request.setAttribute("individual",object);
|
||||
} else {
|
||||
log.error("No custom short view jsp set for VClass "+clas.getName()+" so cannot render link name correctly");
|
||||
request.setAttribute("objectName",object.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}%>
|
||||
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
||||
<form action="editRequestDispatch.jsp" method="get">
|
||||
<label for="submit"><h2>Are you sure you want to delete the following entry from <em>${propertyName}</em>?</h2></label>
|
||||
<div class="toBeDeleted objProp">
|
||||
<c:choose>
|
||||
<c:when test="${!empty customShortView}">
|
||||
<c:set scope="request" var="individual" value="${individual}"/>
|
||||
<jsp:include page="${customShortView}" flush="true"/>
|
||||
<c:remove var="customShortView"/>
|
||||
</c:when>
|
||||
<c:otherwise>${objectName}</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
|
||||
<input type="hidden" name="y" value="1"/>
|
||||
<input type="hidden" name="cmd" value="delete"/>
|
||||
<v:input type="submit" id="submit" value="Delete" cancel="${param.subjectUri}" />
|
||||
|
||||
</form>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
104
webapp/web/edit/forms/simpleFileUpload.jsp
Normal file
104
webapp/web/edit/forms/simpleFileUpload.jsp
Normal file
|
@ -0,0 +1,104 @@
|
|||
<%-- $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.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
|
||||
|
||||
<%
|
||||
/* Prompts the user for a file to upload and adds a statement between a newly created
|
||||
file resource and the Subject using the incoming predicate. Also try to make
|
||||
an inverse statement. */
|
||||
|
||||
Individual subject = (Individual)request.getAttribute("subject");
|
||||
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
%>
|
||||
|
||||
<v:jsonset var="queryForInverse" >
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
SELECT ?inverse_property
|
||||
WHERE {
|
||||
?inverse_property owl:inverseOf ?predicate
|
||||
}
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3ForEdit" >
|
||||
?subject ?predicate ?fileResource .
|
||||
</v:jsonset>
|
||||
|
||||
<v:jsonset var="n3Inverse" >
|
||||
?fileResource ?inverseProp ?subject.
|
||||
</v:jsonset>
|
||||
|
||||
<c:set var="editjson" scope="request">
|
||||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
|
||||
"subject" : [ "subject", "${subjectUriJson}" ] ,
|
||||
"predicate" : [ "predicate", "${predicateUriJson}" ],
|
||||
"object" : [ "fileResource" , "${objectUriJson}" , "URI"],
|
||||
|
||||
"n3required" : [ "${n3ForEdit}" ],
|
||||
"n3optional" : [ "${n3Inverse}" ],
|
||||
"newResources" : { },
|
||||
|
||||
"urisInScope" : { },
|
||||
"literalsInScope" : { },
|
||||
|
||||
"urisOnForm" : [ ],
|
||||
"literalsOnForm" : [ ],
|
||||
"filesOnForm" : [ "fileResource" ],
|
||||
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : {"inverseProp" : "${queryForInverse}" },
|
||||
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"fields" : { "fileResource" : {
|
||||
"newResource" : "false",
|
||||
"queryForExisting" : { },
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "FILE_UPLOAD",
|
||||
"subjectUri" : "",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "${fileResourceClass}",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"literalOptions" : [ ] ,
|
||||
"assertions" : ["${n3ForEdit}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
</c:set>
|
||||
|
||||
<% /* now put edit configuration Json object into session */
|
||||
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
|
||||
EditConfiguration.putConfigInSession(editConfig, session);
|
||||
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
|
||||
editConfig.prepareForObjPropUpdate( model );
|
||||
} else {
|
||||
editConfig.prepareForNonUpdate( model );
|
||||
}
|
||||
%>
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
||||
<h2>Upload a File</h2>
|
||||
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" ENCTYPE="multipart/form-data" method="POST">
|
||||
File <v:input type="file" id="fileResource" />
|
||||
<v:input type="submit" id="submit" value="submit" cancel="${param.subjectUri}"/>
|
||||
</form>
|
||||
|
||||
<jsp:include page="${postForm}"/>
|
12
webapp/web/edit/login.jsp
Normal file
12
webapp/web/edit/login.jsp
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
|
||||
<div align="center">The experimental in-line editing is disabled for this system.</div>
|
||||
|
||||
<c:url value="/" var="siteRoot"/>
|
||||
<div align="center">
|
||||
<button type="button"
|
||||
onclick="javascript:document.location.href='${siteRoot}'">
|
||||
Return to main site</button>
|
||||
|
||||
|
42
webapp/web/edit/messages/dataPropertyStatementMissing.jsp
Normal file
42
webapp/web/edit/messages/dataPropertyStatementMissing.jsp
Normal file
|
@ -0,0 +1,42 @@
|
|||
<%-- $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"/>
|
265
webapp/web/edit/messages/datapropertyBackButtonProblems.jsp
Normal file
265
webapp/web/edit/messages/datapropertyBackButtonProblems.jsp
Normal file
|
@ -0,0 +1,265 @@
|
|||
<%-- $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.vedit.beans.LoginFormBean" %>
|
||||
<%@ 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.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.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.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");
|
||||
|
||||
if( session == null)
|
||||
throw new Error("need to have session");
|
||||
%>
|
||||
<%
|
||||
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.CURATOR)) {
|
||||
%><c:redirect url="<%= Controllers.LOGIN %>" /><%
|
||||
}
|
||||
|
||||
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, 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 processDatapropRdfForm.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 ));
|
||||
}
|
||||
%>
|
42
webapp/web/edit/messages/noEditConfigFound.jsp
Normal file
42
webapp/web/edit/messages/noEditConfigFound.jsp
Normal file
|
@ -0,0 +1,42 @@
|
|||
<%-- $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"/>
|
472
webapp/web/edit/n3Delete.jsp
Normal file
472
webapp/web/edit/n3Delete.jsp
Normal file
|
@ -0,0 +1,472 @@
|
|||
<%-- $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.vedit.beans.LoginFormBean" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
<%@ page import="java.io.StringReader" %>
|
||||
<%@ page import="java.util.*" %>
|
||||
<%@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.ServletIdentifierBundleFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
|
||||
<%-- N3 based deletion.
|
||||
|
||||
Build up the n3 using the fields from an edit configuration and then remove
|
||||
all of those statements from the systems model. In general this should
|
||||
do the same thing as an update with processRdfForm2.jsp but it should just
|
||||
build the assertions graph and remove that from the system model.
|
||||
|
||||
--%>
|
||||
<%
|
||||
if( session == null)
|
||||
throw new Error("need to have session");
|
||||
boolean selfEditing = VitroRequestPrep.isSelfEditing(request);
|
||||
if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
|
||||
%><c:redirect url="<%= Controllers.LOGIN %>" /><%
|
||||
}
|
||||
|
||||
/* the post parameters seem to get consumed by the parsing so
|
||||
* we have to make a copy. */
|
||||
Map <String,List<String>> queryParameters = null;
|
||||
queryParameters = request.getParameterMap();
|
||||
|
||||
List<String> errorMessages = new ArrayList<String>();
|
||||
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request,queryParameters);
|
||||
if( editConfig == null ){
|
||||
%><jsp:forward page="/edit/messages/noEditConfigFound.jsp"/><%
|
||||
}
|
||||
EditN3Generator n3Subber = editConfig.getN3Generator();
|
||||
EditSubmission submission = new EditSubmission(queryParameters, editConfig);
|
||||
|
||||
Map<String,String> errors = submission.getValidationErrors();
|
||||
EditSubmission.putEditSubmissionInSession(session,submission);
|
||||
|
||||
if( errors != null && ! errors.isEmpty() ){
|
||||
String form = editConfig.getFormUrl();
|
||||
request.setAttribute("formUrl", form);
|
||||
%><jsp:forward page="${formUrl}"/><%
|
||||
return;
|
||||
}
|
||||
|
||||
List<Model> requiredAssertionsToDelete = new ArrayList<Model>();
|
||||
List<Model> optionalAssertionsToDelete = new ArrayList<Model>();
|
||||
|
||||
boolean requestIsAnValidDelete = editConfig.getObject() != null && editConfig.getObject().trim().length() > 0;
|
||||
if( requestIsAnValidDelete ){
|
||||
if( log.isDebugEnabled()) log.debug("deleting using n3Delete.jsp; resource: " + editConfig.getObject() );
|
||||
|
||||
List<String> n3Required = editConfig.getN3Required();
|
||||
List<String> n3Optional = editConfig.getN3Optional();
|
||||
|
||||
/* ****************** URIs and Literals in Scope ************** */
|
||||
n3Required = subInUris( editConfig.getUrisInScope(), n3Required);
|
||||
n3Optional = subInUris( editConfig.getUrisInScope(), n3Optional);
|
||||
if(log.isDebugEnabled()) logRequuiredOpt("subsititued in URIs from scope ",n3Required,n3Optional);
|
||||
|
||||
n3Required = n3Subber.subInLiterals( editConfig.getLiteralsInScope(), n3Required);
|
||||
n3Optional = n3Subber.subInLiterals( editConfig.getLiteralsInScope(), n3Optional);
|
||||
if(log.isDebugEnabled()) logRequuiredOpt("subsititued in Literals from scope ",n3Required,n3Optional);
|
||||
|
||||
//no new resources
|
||||
|
||||
//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 );
|
||||
}
|
||||
requiredAssertionsToDelete.addAll(requiredNewModels);
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
optionalAssertionsToDelete.addAll(optionalNewModels);
|
||||
|
||||
//////////////// from update of processRdfForm2.jsp /////////////
|
||||
|
||||
Map<String,List<String>> fieldAssertions = null;
|
||||
if( editConfig.getObject() != null && editConfig.getObject().length() > 0){
|
||||
fieldAssertions = fieldsToAssertionMap(editConfig.getFields());
|
||||
}else{
|
||||
fieldAssertions = new HashMap<String,List<String>>();
|
||||
}
|
||||
|
||||
Map<String,List<String>> fieldRetractions = null;
|
||||
if( editConfig.getObject() != null && editConfig.getObject().length() > 0){
|
||||
fieldRetractions = fieldsToRetractionMap(editConfig.getFields());
|
||||
}else{
|
||||
fieldRetractions = new HashMap<String,List<String>>();
|
||||
}
|
||||
|
||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
||||
fieldAssertions = n3Subber.substituteIntoValues( submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions);
|
||||
if(log.isDebugEnabled()) logAddRetract("subsititued in literals from form",fieldAssertions,fieldRetractions);
|
||||
//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("subsititued in URIs and Literals from scope",fieldAssertions,fieldRetractions);
|
||||
|
||||
//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);
|
||||
|
||||
/* For the delete don't check that field changed, just build assertions */
|
||||
log.debug("making delete graph for field " + fieldName );
|
||||
/* if the field was a checkbox then we need to something special, don't know what that is yet */
|
||||
|
||||
List<String> assertions = fieldAssertions.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){
|
||||
errorMessages.add("error processing N3 assertion string from field " + fieldName + "\n"+
|
||||
t.getMessage() + '\n' +
|
||||
"n3: \n" + n3 );
|
||||
}
|
||||
}
|
||||
}
|
||||
requiredAssertionsToDelete.addAll( requiredFieldAssertions );
|
||||
} else {
|
||||
throw new Error("No object specified, cannot do delete");
|
||||
}
|
||||
|
||||
//The requiredNewModels and the optionalNewModels could be handled differently
|
||||
//but for now we'll just do them the same
|
||||
requiredAssertionsToDelete.addAll(optionalAssertionsToDelete);
|
||||
Model allPossibleToDelete = ModelFactory.createDefaultModel();
|
||||
for( Model model : requiredAssertionsToDelete ) {
|
||||
allPossibleToDelete.add( model );
|
||||
}
|
||||
|
||||
OntModel queryModel = editConfig.getQueryModelSelector().getModel(request,application);
|
||||
if( editConfig.isUseDependentResourceDelete() ){
|
||||
Model depResRetractions =
|
||||
DependentResourceDeleteJena
|
||||
.getDependentResourceDeleteForChange(null,allPossibleToDelete,queryModel);
|
||||
allPossibleToDelete.add( depResRetractions );
|
||||
}
|
||||
|
||||
OntModel writeModel = editConfig.getWriteModelSelector().getModel(request,application);
|
||||
String editorUri = EditN3Utils.getEditorUri(request,session,application);
|
||||
Lock lock = null;
|
||||
try{
|
||||
lock = writeModel.getLock();
|
||||
lock.enterCriticalSection(Lock.WRITE);
|
||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,true));
|
||||
writeModel.remove(allPossibleToDelete);
|
||||
}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();
|
||||
}
|
||||
%>
|
||||
|
||||
<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;
|
||||
}
|
||||
|
||||
|
||||
//******************************************
|
||||
//Use N3Subber instead of these utility methods
|
||||
|
||||
|
||||
public Map<String,List<String>> substituteIntoValues(Map<String,String> varsToUris,
|
||||
Map<String,String> varsToLiterals,
|
||||
Map<String,List<String>> namesToN3 ){
|
||||
Map<String,List<String>> outHash = new HashMap<String,List<String>>();
|
||||
for(String fieldName : namesToN3.keySet()){
|
||||
List<String> n3strings = namesToN3.get(fieldName);
|
||||
List<String> newList = new ArrayList<String>();
|
||||
if( varsToUris != null)
|
||||
newList = subInUris(varsToUris, n3strings);
|
||||
if( varsToLiterals != null)
|
||||
newList = subInLiterals(varsToLiterals, newList);
|
||||
outHash.put(fieldName, newList);
|
||||
}
|
||||
return outHash;
|
||||
}
|
||||
|
||||
|
||||
public List<String> subInUris(Map<String,String> varsToVals, List<String> targets){
|
||||
if( varsToVals == null || varsToVals.isEmpty() ) return targets;
|
||||
ArrayList<String> outv = new ArrayList<String>();
|
||||
for( String target : targets){
|
||||
String temp = target;
|
||||
for( String key : varsToVals.keySet()) {
|
||||
temp = subInUris( key, varsToVals.get(key), temp) ;
|
||||
}
|
||||
outv.add(temp);
|
||||
}
|
||||
return outv;
|
||||
}
|
||||
|
||||
|
||||
public String subInUris(String var, String value, String target){
|
||||
if( var == null || var.length() == 0 || value==null )
|
||||
return target;
|
||||
String varRegex = "\\?" + var;
|
||||
String out = target.replaceAll(varRegex,"<"+value+">");
|
||||
if( out != null && out.length() > 0 )
|
||||
return out;
|
||||
else
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
public List<String>subInUris(String var, String value, List<String> targets){
|
||||
ArrayList<String> outv =new ArrayList<String>();
|
||||
for( String target : targets){
|
||||
outv.add( subInUris( var,value, target) ) ;
|
||||
}
|
||||
return outv;
|
||||
}
|
||||
|
||||
|
||||
public List<String> subInLiterals(Map<String,String> varsToVals, List<String> targets){
|
||||
if( varsToVals == null || varsToVals.isEmpty()) return targets;
|
||||
|
||||
ArrayList<String> outv =new ArrayList<String>();
|
||||
for( String target : targets){
|
||||
String temp = target;
|
||||
for( String key : varsToVals.keySet()) {
|
||||
temp = subInLiterals( key, varsToVals.get(key), temp);
|
||||
}
|
||||
outv.add(temp);
|
||||
}
|
||||
return outv;
|
||||
}
|
||||
|
||||
|
||||
public List<String>subInLiterals(String var, String value, List<String> targets){
|
||||
ArrayList<String> outv =new ArrayList<String>();
|
||||
for( String target : targets){
|
||||
outv.add( subInLiterals( var,value, target) ) ;
|
||||
}
|
||||
return outv;
|
||||
}
|
||||
|
||||
|
||||
public String subInLiterals(String var, String value, String target){
|
||||
String varRegex = "\\?" + var;
|
||||
String out = target.replaceAll(varRegex,'"'+value+'"'); //*** THIS NEEDS TO BE ESCAPED for N3 (thats python escaping)
|
||||
if( out != null && out.length() > 0 )
|
||||
return out ;
|
||||
else
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
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 + Math.abs( 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();
|
||||
|
||||
//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 logRequuiredOpt(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 ));
|
||||
}
|
||||
%>
|
76
webapp/web/edit/postEditCleanUp.jsp
Normal file
76
webapp/web/edit/postEditCleanUp.jsp
Normal file
|
@ -0,0 +1,76 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
<%@page import="org.apache.commons.logging.Log"%>
|
||||
<%@page import="org.apache.commons.logging.LogFactory"%>
|
||||
<%@ 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 redirectTo = null;
|
||||
String urlPattern = null;
|
||||
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 && editConfig.getEntityToReturnTo() != null ){
|
||||
String predicateUri = editConfig.getPredicateUri();
|
||||
log.debug("Return to property after submitting form: " + predicateUri);
|
||||
%>
|
||||
<c:set var="predicateUri" value="<%=predicateUri%>" />
|
||||
<c:set var="localName" value="${fn:substringAfter(predicateUri, '#')}" />
|
||||
<%
|
||||
|
||||
if( editConfig.getEntityToReturnTo().startsWith("?") ){
|
||||
redirectTo = (String)request.getAttribute("entityToReturnTo");
|
||||
}else{
|
||||
redirectTo = editConfig.getEntityToReturnTo();
|
||||
}
|
||||
|
||||
}
|
||||
if( editConfig != null && editConfig.getUrlPatternToReturnTo() != null){
|
||||
urlPattern = editConfig.getUrlPatternToReturnTo();
|
||||
}
|
||||
}
|
||||
|
||||
if( redirectTo != null ){
|
||||
request.setAttribute("redirectTo",redirectTo); %>
|
||||
|
||||
<%-- <c:redirect url="/entity">
|
||||
<c:param name="uri" value="${redirectTo}" />
|
||||
<c:param name="property" value="${localName}" />
|
||||
</c:redirect> --%>
|
||||
|
||||
<% if( urlPattern != null && urlPattern.endsWith("entity")){ %>
|
||||
<%-- Here we're building the redirect URL to include an (unencoded) fragment identifier such as: #propertyName --%>
|
||||
<c:url context="/" var="encodedUrl" value="/entity">
|
||||
<c:param name="uri" value="${redirectTo}" />
|
||||
</c:url>
|
||||
<c:redirect url="${encodedUrl}${'#'}${localName}" />
|
||||
<% } else {
|
||||
request.setAttribute("urlPattern",urlPattern);%>
|
||||
<c:url context="/" var="encodedUrl" value="${urlPattern}">
|
||||
<c:param name="uri" value="${redirectTo}" />
|
||||
</c:url>
|
||||
<c:redirect url="${encodedUrl}${'#'}${localName}" />
|
||||
<%} %>
|
||||
<% } else { %>
|
||||
<c:redirect url="<%= Controllers.LOGIN %>" />
|
||||
<% } %>
|
||||
|
||||
|
||||
<%!
|
||||
Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.edit.postEditCleanUp.jsp");
|
||||
%>
|
||||
|
||||
|
||||
|
419
webapp/web/edit/processDatapropRdfForm.jsp
Normal file
419
webapp/web/edit/processDatapropRdfForm.jsp
Normal file
|
@ -0,0 +1,419 @@
|
|||
<%-- $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.vedit.beans.LoginFormBean" %>
|
||||
<%@ 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.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.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.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.ServletIdentifierBundleFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%>
|
||||
<%@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.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"
|
||||
|
||||
--%>
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.processDatapropRdfForm.jsp");
|
||||
%>
|
||||
<%
|
||||
log.debug("Starting processDatapropRdfForm.jsp");
|
||||
|
||||
if( session == null)
|
||||
throw new Error("need to have session");
|
||||
%>
|
||||
<%
|
||||
boolean selfEditing = VitroRequestPrep.isSelfEditing(request);
|
||||
if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
|
||||
%><c:redirect url="<%= Controllers.LOGIN %>" /><%
|
||||
}
|
||||
|
||||
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( 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,session,application);
|
||||
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());
|
||||
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(EditSubmission submission,
|
||||
EditConfiguration editConfig, Individual subject,
|
||||
WebappDaoFactory wdf) {
|
||||
if (editConfig.getDatapropKey() == null
|
||||
|| editConfig.getDatapropKey().length() == 0)
|
||||
return false;
|
||||
DataPropertyStatement dps = RdfLiteralHash.getDataPropertyStmtByHash(
|
||||
subject, Integer.parseInt(editConfig.getDatapropKey()));
|
||||
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 ("".equals(value.getLexicalForm())) {
|
||||
log.debug("Submission was a single field 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));
|
||||
}%>
|
484
webapp/web/edit/processRdfForm2.jsp
Normal file
484
webapp/web/edit/processRdfForm2.jsp
Normal file
|
@ -0,0 +1,484 @@
|
|||
<%-- $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.vedit.beans.LoginFormBean" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %>
|
||||
<%@ page import="java.io.StringReader" %>
|
||||
<%@ page import="java.util.*" %>
|
||||
<%@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.ServletIdentifierBundleFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.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.ModelChangePreprocessor"%>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
|
||||
<%@ 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.
|
||||
--%>
|
||||
<%
|
||||
if( session == null)
|
||||
throw new Error("need to have session");
|
||||
boolean selfEditing = VitroRequestPrep.isSelfEditing(request);
|
||||
if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
|
||||
%>
|
||||
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena"%><c:redirect url="<%= Controllers.LOGIN %>" />
|
||||
<%
|
||||
}
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
|
||||
/* 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>();
|
||||
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq,queryParameters);
|
||||
if( editConfig == null ){
|
||||
%><jsp:forward page="/edit/messages/noEditConfigFound.jsp"/><%
|
||||
}
|
||||
EditN3Generator n3Subber = editConfig.getN3Generator();
|
||||
EditSubmission submission = new EditSubmission(queryParameters,editConfig);
|
||||
|
||||
/* 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);
|
||||
%><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 a 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("subsititued 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("subsititued 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(),resourcesModel);
|
||||
fieldAssertions = n3Subber.substituteIntoValues(varToNewResource, null, fieldAssertions);
|
||||
if(log.isDebugEnabled()) logAddRetract("subsititued 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()) logRequuiredOpt("subsititued 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()) logRequuiredOpt("subsititued 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()) logRequuiredOpt("subsititued 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()) logRequuiredOpt("subsititued in Literals from scope ",n3Required,n3Optional);
|
||||
|
||||
/* ****************** 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);
|
||||
n3Optional = n3Subber.subInUris( varToNewResource, n3Optional);
|
||||
if(log.isDebugEnabled()) logRequuiredOpt("subsititued 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 );
|
||||
}
|
||||
}
|
||||
|
||||
// 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,session,application);
|
||||
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, 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 + Math.abs( 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();
|
||||
|
||||
//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 logRequuiredOpt(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 ));
|
||||
}
|
||||
%>
|
113
webapp/web/edit/selfeditcheck.jsp
Normal file
113
webapp/web/edit/selfeditcheck.jsp
Normal file
|
@ -0,0 +1,113 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ 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.auth.identifier.SelfEditingIdentifierFactory.NetId"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%>
|
||||
<%@page import="java.io.IOException"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundleFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
|
||||
|
||||
<h1>SelfEditing Sanity Check</h1>
|
||||
|
||||
<h3>Is there a Factory that will create self editing identifiers?</h3>
|
||||
<%
|
||||
ServletIdentifierBundleFactory sibf = ServletIdentifierBundleFactory.getIdentifierBundleFactory(application);
|
||||
String found = "Self editing identifier factory found.";
|
||||
for( IdentifierBundleFactory ibf : sibf ){
|
||||
if( ibf instanceof SelfEditingIdentifierFactory ){
|
||||
found = "Found a self editing identifier factory.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
%>
|
||||
<%= found %>
|
||||
|
||||
|
||||
<h3>Is there a self editing policy in the context?</h3>
|
||||
<%
|
||||
ServletPolicyList spl = ServletPolicyList.getPolicies(application);
|
||||
SelfEditingPolicy sePolicy = null;
|
||||
ListIterator it = spl.listIterator();
|
||||
found = "Could not find a SelfEditingPolicy";
|
||||
while(it.hasNext()){
|
||||
PolicyIface p = (PolicyIface)it.next();
|
||||
if( p instanceof SelfEditingPolicy ){
|
||||
found = "Found a SelfEditingPolicy";
|
||||
sePolicy = (SelfEditingPolicy)p;
|
||||
}
|
||||
}
|
||||
%>
|
||||
<%= found %>
|
||||
|
||||
<h3>Do you have a REMOTE_USER header from CUWebAuth?</h3>
|
||||
|
||||
<% String user = request.getHeader("REMOTE_USER");
|
||||
if( user != null && user.length() > 0){
|
||||
%> Found a remote user of <%= user %>. <%
|
||||
}else{
|
||||
%> Could not find a remote user. Maybe you are not logged into CUWebAutn? <%
|
||||
}
|
||||
%>
|
||||
<h3>Check if we can get a SelfEditingIdentifer for <%= user %></h3>
|
||||
<%
|
||||
SelfEditingIdentifierFactory.SelfEditing selfEditingId = null;
|
||||
IdentifierBundle ib = null;
|
||||
if( user != null && user.length() > 0){
|
||||
ib = sibf.getIdentifierBundle(request,session,application);
|
||||
if( ib != null ) {
|
||||
for( Object obj : ib){
|
||||
if( obj instanceof SelfEditingIdentifierFactory.SelfEditing )
|
||||
selfEditingId = (SelfEditingIdentifierFactory.SelfEditing) obj;
|
||||
}
|
||||
if( selfEditingId != null )
|
||||
found = "found a SelfEditingId " + selfEditingId.getValue();
|
||||
else
|
||||
found = "Cound not find a SelfEditingId";
|
||||
}else{
|
||||
found = "Could not get any identififers";
|
||||
}
|
||||
%>
|
||||
<%= found %>
|
||||
<%}else{%>
|
||||
Cannot check becaue user is <%= user %>.
|
||||
<%} %>
|
||||
|
||||
|
||||
<h3>Is that SelfEditingIdentifer blacklisted?</h3>
|
||||
<% if( user == null || user.length() == 0 ){ %>
|
||||
No REMOTE_USER to check
|
||||
<% }else if( selfEditingId == null ){ %>
|
||||
no SelfEditingId to check
|
||||
<% }else if( selfEditingId.getBlacklisted() != null){%>
|
||||
SelfEditingId blacklisted because of <%= selfEditingId.getBlacklisted() %>
|
||||
<% } else {%>
|
||||
SelfEditingId is not blacklisted.
|
||||
<% } %>
|
||||
|
||||
<h3>Can an object property be edited with this SelfEditingId and Policy?</h3>
|
||||
<% if( user == null || selfEditingId == null ){ %>
|
||||
No
|
||||
<% }else{
|
||||
AddObjectPropStmt whatToAuth = new AddObjectPropStmt(
|
||||
selfEditingId.getValue(),"http://mannlib.cornell.edu/fine#prp999" ,"http://mannlib.cornell.edu/fine#prp999");
|
||||
PolicyDecision pdecison = sePolicy.isAuthorized(ib, whatToAuth);
|
||||
%> The policy decision was <%= pdecison %>
|
||||
|
||||
<% } %>
|
Loading…
Add table
Add a link
Reference in a new issue