Merge branch 'feature-vivo-57' into develop
This commit is contained in:
commit
68b916a185
16 changed files with 71 additions and 392 deletions
|
@ -25,8 +25,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
|
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
|
||||||
|
|
||||||
public class PrimitiveRdfEdit extends VitroAjaxController {
|
public class PrimitiveRdfEdit extends VitroAjaxController {
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String editorUri = EditN3Utils.getEditorUri(vreq);
|
String editorUri = N3EditUtils.getEditorUri(vreq);
|
||||||
try {
|
try {
|
||||||
Model a = mergeModels(additions);
|
Model a = mergeModels(additions);
|
||||||
Model r = mergeModels(retractions);
|
Model r = mergeModels(retractions);
|
||||||
|
|
|
@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
@ -20,7 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||||
/*
|
/*
|
||||||
* Custom deletion controller to which deletion requests from default property form are sent. May be replaced
|
* Custom deletion controller to which deletion requests from default property form are sent. May be replaced
|
||||||
|
@ -29,16 +31,10 @@ import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||||
public class DeletePropertyController extends FreemarkerHttpServlet {
|
public class DeletePropertyController extends FreemarkerHttpServlet {
|
||||||
private static final Log log = LogFactory.getLog(DeletePropertyController.class);
|
private static final Log log = LogFactory.getLog(DeletePropertyController.class);
|
||||||
|
|
||||||
//since forwarding from edit Request dispatch for now
|
@Override
|
||||||
//TODO: Check what required actions would make sense here
|
protected Actions requiredActions(VitroRequest vreq) {
|
||||||
//public final static Actions REQUIRED_ACTIONS = new Actions(new ManageMenus());
|
return SimplePermission.DO_FRONT_END_EDITING.ACTIONS ;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @Override
|
|
||||||
protected Actions requiredActions(VitroRequest vreq) {
|
|
||||||
return REQUIRED_ACTIONS;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
@ -107,7 +103,7 @@ public class DeletePropertyController extends FreemarkerHttpServlet {
|
||||||
//This is the standard mechanism but note that datapropStmtDelete uses wdf with user aware
|
//This is the standard mechanism but note that datapropStmtDelete uses wdf with user aware
|
||||||
|
|
||||||
//DataProperty prop = EditConfigurationUtils.getDataProperty(vreq);
|
//DataProperty prop = EditConfigurationUtils.getDataProperty(vreq);
|
||||||
String editorUri = EditN3Utils.getEditorUri(vreq);
|
String editorUri = N3EditUtils.getEditorUri(vreq);
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory().getUserAwareDaoFactory(editorUri);
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory().getUserAwareDaoFactory(editorUri);
|
||||||
DataProperty prop = wdf.getDataPropertyDao().getDataPropertyByURI(
|
DataProperty prop = wdf.getDataPropertyDao().getDataPropertyByURI(
|
||||||
EditConfigurationUtils.getPredicateUri(vreq));
|
EditConfigurationUtils.getPredicateUri(vreq));
|
||||||
|
|
|
@ -28,7 +28,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
public class EditConfigurationUtils {
|
public class EditConfigurationUtils {
|
||||||
|
|
|
@ -37,7 +37,6 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardWDF
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.WDFSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.WDFSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,7 +298,7 @@ public class EditConfigurationVTwo {
|
||||||
throw new Error("EditConfiguration.addSystemValues() needs a session");
|
throw new Error("EditConfiguration.addSystemValues() needs a session");
|
||||||
|
|
||||||
/* ********** Get URI of a logged in user ************** */
|
/* ********** Get URI of a logged in user ************** */
|
||||||
String userUri = EditN3Utils.getEditorUri(request);
|
String userUri = N3EditUtils.getEditorUri(request);
|
||||||
log.debug("EditConfiguration.java - checking system value for User URI " + userUri);
|
log.debug("EditConfiguration.java - checking system value for User URI " + userUri);
|
||||||
List<String> userUriList = new ArrayList<String>();
|
List<String> userUriList = new ArrayList<String>();
|
||||||
userUriList.add(userUri);
|
userUriList.add(userUri);
|
||||||
|
|
|
@ -27,7 +27,6 @@ import com.hp.hpl.jena.vocabulary.XSD;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
|
||||||
|
|
||||||
public class MultiValueEditSubmission {
|
public class MultiValueEditSubmission {
|
||||||
|
|
||||||
|
@ -263,7 +262,7 @@ public class MultiValueEditSubmission {
|
||||||
List<Literal> literalsArray = new ArrayList<Literal>();
|
List<Literal> literalsArray = new ArrayList<Literal>();
|
||||||
//now support multiple values
|
//now support multiple values
|
||||||
for(String value:valueList) {
|
for(String value:valueList) {
|
||||||
value = EditN3Utils.stripInvalidXMLChars(value);
|
value = N3EditUtils.stripInvalidXMLChars(value);
|
||||||
//Add to array of literals corresponding to this variable
|
//Add to array of literals corresponding to this variable
|
||||||
if (!StringUtils.isEmpty(value)) {
|
if (!StringUtils.isEmpty(value)) {
|
||||||
literalsArray.add(createLiteral(
|
literalsArray.add(createLiteral(
|
||||||
|
|
|
@ -4,14 +4,21 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.apache.xerces.util.XMLChar;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
|
||||||
|
|
||||||
public class N3EditUtils {
|
public class N3EditUtils {
|
||||||
|
|
||||||
|
@ -118,4 +125,36 @@ public class N3EditUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Several places could give an editor URI. Return the first one. */
|
||||||
|
public static String getEditorUri(HttpServletRequest request) {
|
||||||
|
IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request);
|
||||||
|
|
||||||
|
List<String> uris = new ArrayList<String>();
|
||||||
|
uris.addAll(IsUser.getUserUris(ids));
|
||||||
|
uris.addAll(HasProfile.getProfileUris(ids));
|
||||||
|
uris.add("Unknown N3 Editor");
|
||||||
|
return uris.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips from a string any characters that are not valid in XML 1.0
|
||||||
|
* @param in
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String stripInvalidXMLChars(String in) {
|
||||||
|
if (in == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
StringBuffer out = new StringBuffer();
|
||||||
|
for (int i = 0; i < in.length(); i++) {
|
||||||
|
char c = in.charAt(i);
|
||||||
|
if (!XMLChar.isInvalid(c)) {
|
||||||
|
out.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,23 +316,6 @@ public class ProcessRdfForm {
|
||||||
return rdfModels;
|
return rdfModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: bdc34: what does this check? Why?
|
|
||||||
*/
|
|
||||||
public static boolean isGenerateModelFromField(
|
|
||||||
String fieldName,
|
|
||||||
EditConfigurationVTwo configuration, MultiValueEditSubmission submission) {
|
|
||||||
// if(Utilities.isObjectProperty(configuration, vreq)) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// if(Utilities.isDataProperty(configuration, vreq)) {
|
|
||||||
// if(Utilities.hasFieldChanged(fieldName, configuration, submission)) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void logSubstitue(String msg, List<String> requiredAsserts,
|
protected void logSubstitue(String msg, List<String> requiredAsserts,
|
||||||
List<String> optionalAsserts, List<String> requiredRetracts,
|
List<String> optionalAsserts, List<String> requiredRetracts,
|
||||||
List<String> optionalRetracts) {
|
List<String> optionalRetracts) {
|
||||||
|
|
|
@ -7,6 +7,15 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface that is intended to be used with N3 Editing to
|
||||||
|
* allow a EditConfiguration to specify which models will be used
|
||||||
|
* during editing.
|
||||||
|
*
|
||||||
|
* With Jim's new ModelAccess it may be better to use ModelAccess
|
||||||
|
* identifiers and graph URIs.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public interface ModelSelector {
|
public interface ModelSelector {
|
||||||
public Model getModel(HttpServletRequest request, ServletContext context);
|
public Model getModel(HttpServletRequest request, ServletContext context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultDataPropEmptyField;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultDataPropEmptyField;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
|
||||||
|
|
||||||
public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditSubmissionUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This servlet will convert a request to an EditSubmission,
|
* This servlet will convert a request to an EditSubmission,
|
||||||
|
@ -102,7 +101,7 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
|
|
||||||
N3EditUtils.preprocessModels(changes, configuration, vreq);
|
N3EditUtils.preprocessModels(changes, configuration, vreq);
|
||||||
|
|
||||||
ProcessRdfForm.applyChangesToWriteModel(changes, queryModel, writeModel, EditN3Utils.getEditorUri(vreq) );
|
ProcessRdfForm.applyChangesToWriteModel(changes, queryModel, writeModel, N3EditUtils.getEditorUri(vreq) );
|
||||||
|
|
||||||
//Here we are trying to get the entity to return to URL,
|
//Here we are trying to get the entity to return to URL,
|
||||||
//More involved processing for data property apparently
|
//More involved processing for data property apparently
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.xerces.util.XMLChar;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
|
||||||
|
|
||||||
public class EditN3Utils {
|
|
||||||
/** Several places could give an editor URI. Return the first one. */
|
|
||||||
public static String getEditorUri(HttpServletRequest request) {
|
|
||||||
IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request);
|
|
||||||
|
|
||||||
List<String> uris = new ArrayList<String>();
|
|
||||||
uris.addAll(IsUser.getUserUris(ids));
|
|
||||||
uris.addAll(HasProfile.getProfileUris(ids));
|
|
||||||
uris.add("Unknown N3 Editor");
|
|
||||||
return uris.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strips from a string any characters that are not valid in XML 1.0
|
|
||||||
* @param in
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String stripInvalidXMLChars(String in) {
|
|
||||||
if (in == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StringBuffer out = new StringBuffer();
|
|
||||||
for (int i = 0; i < in.length(); i++) {
|
|
||||||
char c = in.charAt(i);
|
|
||||||
if (!XMLChar.isInvalid(c)) {
|
|
||||||
out.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// public static void addModTimes( Model additions, Model retractions, Model contextModel ){
|
|
||||||
// Property modtime = ResourceFactory.createProperty(VitroVocabulary.MODTIME);
|
|
||||||
// Date time = Calendar.getInstance().getTime();
|
|
||||||
//
|
|
||||||
// //get all resources in additions and retractions that are not types
|
|
||||||
// additions.listStatements()
|
|
||||||
//
|
|
||||||
// Lock lock = contextModel.getLock();
|
|
||||||
// try {
|
|
||||||
//
|
|
||||||
// String existingValue = null;
|
|
||||||
// Statement stmt = res.getProperty(modtime);
|
|
||||||
// if (stmt != null) {
|
|
||||||
// RDFNode object = stmt.getObject();
|
|
||||||
// if (object != null && object.isLiteral()){
|
|
||||||
// existingValue = ((Literal)object).getString();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// String formattedDateStr = xsdDateTimeFormat.format(time);
|
|
||||||
// if ( (existingValue!=null && value == null) || (existingValue!=null && value != null && !(existingValue.equals(formattedDateStr)) ) ) {
|
|
||||||
// model.removeAll(res, modtime, null);
|
|
||||||
// }
|
|
||||||
// if ( (existingValue==null && value != null) || (existingValue!=null && value != null && !(existingValue.equals(formattedDateStr)) ) ) {
|
|
||||||
// model.add(res, modtime, formattedDateStr, XSDDatatype.XSDdateTime);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("Error in updatePropertyDateTimeValue");
|
|
||||||
// log.error(e, e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static List<URIResource>
|
|
||||||
}
|
|
|
@ -1,262 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
|
||||||
|
|
||||||
public class RdfLiteralHash {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(RdfLiteralHash.class.getName());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make a hash based on individual, property, literal and (lang or datatype).
|
|
||||||
*
|
|
||||||
* @param stmt
|
|
||||||
* @return a value between MIN_INTEGER and MAX_INTEGER
|
|
||||||
*/
|
|
||||||
public static int makeRdfLiteralHash( DataPropertyStatement stmt ){
|
|
||||||
if( (stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0)
|
|
||||||
&&
|
|
||||||
(stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0 ) )
|
|
||||||
throw new Error("DataPropertyStatement should not have both a language " +
|
|
||||||
"and a datatype; lang: '" + stmt.getLanguage() + "' datatype: '"+ stmt.getDatatypeURI() + "'");
|
|
||||||
|
|
||||||
if( stmt.getIndividualURI() == null || stmt.getIndividualURI().trim().length() == 0 )
|
|
||||||
throw new Error("Cannot make a hash for a statement with no subject URI");
|
|
||||||
|
|
||||||
if( stmt.getDatapropURI() == null || stmt.getDatapropURI().trim().length() == 0)
|
|
||||||
throw new Error("Cannot make a hash for a statement with no predicate URI");
|
|
||||||
|
|
||||||
String langOrDatatype = "9876NONE";
|
|
||||||
if( stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0){
|
|
||||||
langOrDatatype = stmt.getLanguage();
|
|
||||||
}else{
|
|
||||||
if( stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0){
|
|
||||||
langOrDatatype = stmt.getDatatypeURI();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String hashMe = langOrDatatype + "_" + stmt.getIndividualURI() + "_" + stmt.getDatapropURI() + "_" + stmt.getData();
|
|
||||||
if( log.isDebugEnabled() )
|
|
||||||
log.debug("got hash " + hashMe.hashCode() + " for String '" + hashMe + "'");
|
|
||||||
return hashMe.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param stmt
|
|
||||||
* @param hash
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean doesStmtMatchHash( DataPropertyStatement stmt, int hash){
|
|
||||||
if( stmt == null )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
int stmtHash;
|
|
||||||
try{
|
|
||||||
stmtHash = makeRdfLiteralHash(stmt);
|
|
||||||
log.debug("incoming hash "+hash+" compared to calculated hash "+stmtHash);
|
|
||||||
}catch( Throwable th){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return stmtHash == hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forward to either getDataPropertyStmtByHash or getRdfsLabelStatementByHash, depending on the property.
|
|
||||||
* @param subjectUri,
|
|
||||||
* @param predicateUri,
|
|
||||||
* @param hash
|
|
||||||
* @param model, may not be null
|
|
||||||
* @return a DataPropertyStatement if found or null if not found
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static DataPropertyStatement getPropertyStmtByHash(String subjectUri, String predicateUri, int hash, Model model) {
|
|
||||||
if (subjectUri == null || predicateUri == null ) return null;
|
|
||||||
|
|
||||||
model.enterCriticalSection(false);
|
|
||||||
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
|
||||||
model.getProperty(predicateUri),
|
|
||||||
(RDFNode)null);
|
|
||||||
try {
|
|
||||||
while (stmts.hasNext()) {
|
|
||||||
Statement stmt = stmts.nextStatement();
|
|
||||||
RDFNode node = stmt.getObject();
|
|
||||||
if ( node.isLiteral() ){
|
|
||||||
DataPropertyStatement dps =
|
|
||||||
makeDataPropertyStatementFromStatement(stmt, node);
|
|
||||||
if (doesStmtMatchHash(dps, hash)) {
|
|
||||||
return dps;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
stmts.close();
|
|
||||||
model.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Get data property for subject, predicate and hash. This does not use
|
|
||||||
// * filtering DAOs to avoid the problems when attempting to edit predicates that
|
|
||||||
// * are filtered out.
|
|
||||||
// *
|
|
||||||
// * @param ind, may be null
|
|
||||||
// * @param hash
|
|
||||||
// * @return a DataPropertyStatement if found or null if not found
|
|
||||||
// */
|
|
||||||
// protected static DataPropertyStatement getStatementByHash(String subjectUri, Model model, int hash) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// DataPropertyStatement dps = null;
|
|
||||||
//
|
|
||||||
// // Not using getAllDataPropertyStatements() because it filters out rdfs:labels
|
|
||||||
////
|
|
||||||
//// List<DataPropertyStatement> statements = ind.getDataPropertyStatements();
|
|
||||||
//// if( statements == null ) return null;
|
|
||||||
//// for( DataPropertyStatement dps : statements){
|
|
||||||
//// if( doesStmtMatchHash(dps, hash) )
|
|
||||||
//// return dps;
|
|
||||||
//// }
|
|
||||||
//// return null;
|
|
||||||
//
|
|
||||||
// StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
|
||||||
// model.getProperty(predicateUri),
|
|
||||||
// (RDFNode)null);
|
|
||||||
// try {
|
|
||||||
// while (stmts.hasNext()) {
|
|
||||||
// Statement stmt = stmts.nextStatement();
|
|
||||||
// RDFNode node = stmt.getObject();
|
|
||||||
// if ( node.isLiteral() ){
|
|
||||||
// dps = makeDataPropertyStatementFromStatement(stmt, node);
|
|
||||||
// if (doesStmtMatchHash(dps, hash)) {
|
|
||||||
// return dps;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //} catch {
|
|
||||||
//
|
|
||||||
// } finally{
|
|
||||||
// stmts.close();
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get data property for subject, predicate and hash. This does not use
|
|
||||||
* filtering DAOs to avoid the problems when attempting to edit predicates that
|
|
||||||
* are filtered out.
|
|
||||||
*
|
|
||||||
* @param ind, may be null
|
|
||||||
* @param hash
|
|
||||||
* @return a DataPropertyStatement if found or null if not found
|
|
||||||
*/
|
|
||||||
// protected static DataPropertyStatement getStatementByHash(String subjectUri, String predicateUri, Model model, int hash) {
|
|
||||||
// // Not using getAllDataPropertyStatements() because it filters out rdfs:labels
|
|
||||||
////
|
|
||||||
//// List<DataPropertyStatement> statements = ind.getDataPropertyStatements();
|
|
||||||
//// if( statements == null ) return null;
|
|
||||||
//// for( DataPropertyStatement dps : statements){
|
|
||||||
//// if( doesStmtMatchHash(dps, hash) )
|
|
||||||
//// return dps;
|
|
||||||
//// }
|
|
||||||
//// return null;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// model.enterCriticalSection(false);
|
|
||||||
// StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
|
||||||
// model.getProperty(predicateUri),
|
|
||||||
// (RDFNode)null);
|
|
||||||
// try {
|
|
||||||
// while (stmts.hasNext()) {
|
|
||||||
// Statement stmt = stmts.nextStatement();
|
|
||||||
// RDFNode node = stmt.getObject();
|
|
||||||
// if ( node.isLiteral() ){
|
|
||||||
// DataPropertyStatement dps =
|
|
||||||
// makeDataPropertyStatementFromStatement(stmt, node);
|
|
||||||
// if (doesStmtMatchHash(dps, hash)) {
|
|
||||||
// return dps;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// } finally {
|
|
||||||
// stmts.close();
|
|
||||||
// model.leaveCriticalSection();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public static int makeRdfsLabelLiteralHash( Individual subject, String value, Model model) {
|
|
||||||
|
|
||||||
String subjectUri = subject.getURI();
|
|
||||||
String predicateUri = VitroVocabulary.LABEL;
|
|
||||||
|
|
||||||
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
|
||||||
model.getProperty(predicateUri),
|
|
||||||
(RDFNode) null);
|
|
||||||
DataPropertyStatement dps = null;
|
|
||||||
int hash = 0;
|
|
||||||
int count = 0;
|
|
||||||
try {
|
|
||||||
while (stmts.hasNext()) {
|
|
||||||
Statement stmt = stmts.nextStatement();
|
|
||||||
RDFNode node = stmt.getObject();
|
|
||||||
if (node.isLiteral()) {
|
|
||||||
count++;
|
|
||||||
dps = makeDataPropertyStatementFromStatement(stmt, node);
|
|
||||||
hash = makeRdfLiteralHash(dps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
stmts.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( count == 1 ) {
|
|
||||||
return hash;
|
|
||||||
} else if( count == 0 ){
|
|
||||||
log.debug("No data property statement for " +
|
|
||||||
"subject:" + subjectUri + "\npredicate:" + predicateUri + "\nvalue: " + value);
|
|
||||||
throw new IllegalArgumentException("Could not create RdfLiteralHash because " +
|
|
||||||
"there was no data property statement with the given value.");
|
|
||||||
} else{
|
|
||||||
log.debug("Multiple data property statements for " +
|
|
||||||
"subject:" + subjectUri + "\npredicate:" + predicateUri + "\nvalue: " + value);
|
|
||||||
throw new IllegalArgumentException("Could not create RdfLiteralHash because " +
|
|
||||||
"there were multiple data property statements with the given value.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DataPropertyStatement makeDataPropertyStatementFromStatement(Statement statement, RDFNode node) {
|
|
||||||
|
|
||||||
Literal lit = (Literal) node.as(Literal.class);
|
|
||||||
String value = lit.getLexicalForm();
|
|
||||||
String lang = lit.getLanguage();
|
|
||||||
String datatypeUri = lit.getDatatypeURI();
|
|
||||||
|
|
||||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
|
||||||
dps.setDatatypeURI(datatypeUri);
|
|
||||||
dps.setLanguage(lang);
|
|
||||||
dps.setData(value);
|
|
||||||
dps.setDatapropURI(statement.getPredicate().getURI());
|
|
||||||
dps.setIndividualURI(statement.getSubject().getURI());
|
|
||||||
|
|
||||||
return dps;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
||||||
|
|
||||||
public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
||||||
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This allows the template to treat an rdfs:label like a data property statement, and thus
|
* This allows the template to treat an rdfs:label like a data property statement, and thus
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
|
|
||||||
|
|
||||||
public class EditN3UtilsTest {
|
public class EditN3UtilsTest {
|
||||||
|
@ -27,7 +27,7 @@ public class EditN3UtilsTest {
|
||||||
|
|
||||||
Assert.assertFalse(isSerializableAsXML(m));
|
Assert.assertFalse(isSerializableAsXML(m));
|
||||||
|
|
||||||
String stripped = EditN3Utils.stripInvalidXMLChars(
|
String stripped = N3EditUtils.stripInvalidXMLChars(
|
||||||
containsInvalidXMLChars);
|
containsInvalidXMLChars);
|
||||||
Assert.assertEquals(clean, stripped);
|
Assert.assertEquals(clean, stripped);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
||||||
|
|
||||||
public class RdfLiteralHashTest {
|
public class RdfLiteralHashTest {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue