Working N3 editing of display model.
This commit is contained in:
parent
f77edc315e
commit
5b89150d4f
3 changed files with 70 additions and 28 deletions
|
@ -98,7 +98,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Package access to allow for unit testing. */
|
/** Package access to allow for unit testing. */
|
||||||
void processChanges(String editorUri, OntModel writeModel,
|
void processChanges(String editorUri, Model writeModel,
|
||||||
Model toBeAdded, Model toBeRetracted) throws Exception {
|
Model toBeAdded, Model toBeRetracted) throws Exception {
|
||||||
Lock lock = null;
|
Lock lock = null;
|
||||||
log.debug("Model to be retracted is");
|
log.debug("Model to be retracted is");
|
||||||
|
@ -108,13 +108,17 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
|
||||||
try {
|
try {
|
||||||
lock = writeModel.getLock();
|
lock = writeModel.getLock();
|
||||||
lock.enterCriticalSection(Lock.WRITE);
|
lock.enterCriticalSection(Lock.WRITE);
|
||||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri, true));
|
if( writeModel instanceof OntModel){
|
||||||
|
((OntModel)writeModel).getBaseModel().notifyEvent(new EditEvent(editorUri, true));
|
||||||
|
}
|
||||||
writeModel.add(toBeAdded);
|
writeModel.add(toBeAdded);
|
||||||
writeModel.remove(toBeRetracted);
|
writeModel.remove(toBeRetracted);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new Exception("Error while modifying model \n" + t.getMessage());
|
throw new Exception("Error while modifying model \n" + t.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri, false));
|
if( writeModel instanceof OntModel){
|
||||||
|
((OntModel)writeModel).getBaseModel().notifyEvent(new EditEvent(editorUri, false));
|
||||||
|
}
|
||||||
lock.leaveCriticalSection();
|
lock.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +147,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel getWriteModel(VitroRequest vreq){
|
private Model getWriteModel(VitroRequest vreq){
|
||||||
return StandardModelSelector.selector.getModel(vreq,getServletContext());
|
return StandardModelSelector.selector.getModel(vreq,getServletContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,22 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
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.configuration.IdModelSelector;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
|
||||||
|
|
||||||
public abstract class BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
public abstract class BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
|
@ -54,13 +63,10 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
//Originally included in edit request dispatch controller but moved here due to
|
//Originally included in edit request dispatch controller but moved here due to
|
||||||
//exceptions such as default add missing individual form
|
//exceptions such as default add missing individual form
|
||||||
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
||||||
//This used to get the model from the servlet context
|
//setup the model selectors for query, write and display models on editConfig
|
||||||
// Model model = (Model) getServletContext().getAttribute("jenaOntModel");
|
setupModelSelectorsFromVitroRequest(vreq, editConfig);
|
||||||
|
|
||||||
//PROBLEM: this is returning the jenaOntModel
|
OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel");
|
||||||
// but we want the current abox model which might have
|
|
||||||
// been set to the display model or something.
|
|
||||||
Model model = vreq.getJenaOntModel();
|
|
||||||
|
|
||||||
if( editConfig.getSubjectUri() == null)
|
if( editConfig.getSubjectUri() == null)
|
||||||
editConfig.setSubjectUri( EditConfigurationUtils.getSubjectUri(vreq));
|
editConfig.setSubjectUri( EditConfigurationUtils.getSubjectUri(vreq));
|
||||||
|
@ -73,13 +79,41 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
// editing existing object
|
// editing existing object
|
||||||
if( editConfig.getObject() == null)
|
if( editConfig.getObject() == null)
|
||||||
editConfig.setObject( EditConfigurationUtils.getObjectUri(vreq));
|
editConfig.setObject( EditConfigurationUtils.getObjectUri(vreq));
|
||||||
editConfig.prepareForObjPropUpdate(model);
|
editConfig.prepareForObjPropUpdate(queryModel);
|
||||||
} else if( dataKey != null ) { // edit of a data prop statement
|
} else if( dataKey != null ) { // edit of a data prop statement
|
||||||
//do nothing since the data prop form generator must take care of it
|
//do nothing since the data prop form generator must take care of it
|
||||||
editConfig.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
editConfig.prepareForDataPropUpdate(queryModel, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||||
} else{
|
} else{
|
||||||
//this might be a create new or a form
|
//this might be a create new or a form
|
||||||
editConfig.prepareForNonUpdate(model);
|
editConfig.prepareForNonUpdate(queryModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the model selectors using the models set in the VitroRequest. Call this
|
||||||
|
* if the form should use the selectors from the VitroRequest. Don't call this
|
||||||
|
* and setup specific selectors if the custom form needs to always target specific
|
||||||
|
* models.
|
||||||
|
*/
|
||||||
|
public void setupModelSelectorsFromVitroRequest(VitroRequest vreq, EditConfigurationVTwo editConfig){
|
||||||
|
if( ! StringUtils.isEmpty( vreq.getNameForWriteModel() ) ){
|
||||||
|
editConfig.setWriteModelSelector(new IdModelSelector( vreq.getNameForWriteModel() ));
|
||||||
|
editConfig.setWriteModelId( vreq.getNameForWriteModel());
|
||||||
|
}else{
|
||||||
|
editConfig.setWriteModelSelector( StandardModelSelector.selector );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ! StringUtils.isEmpty( vreq.getNameForABOXModel() )){
|
||||||
|
editConfig.setQueryModelSelector( new IdModelSelector(vreq.getNameForABOXModel() ));
|
||||||
|
editConfig.setResourceModelSelector( new IdModelSelector(vreq.getNameForABOXModel() ));
|
||||||
|
editConfig.setAboxModelId(vreq.getNameForABOXModel());
|
||||||
|
}else{
|
||||||
|
editConfig.setQueryModelSelector( StandardModelSelector.selector );
|
||||||
|
editConfig.setResourceModelSelector( StandardModelSelector.selector );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ! StringUtils.isEmpty( vreq.getNameForTBOXModel() )){
|
||||||
|
editConfig.setTboxModelId(vreq.getNameForTBOXModel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,19 +102,10 @@ public class DefaultDeleteGenerator extends BaseEditConfigurationGenerator imple
|
||||||
this.initObjectParameters(vreq);
|
this.initObjectParameters(vreq);
|
||||||
this.processObjectPropForm(vreq, editConfiguration);
|
this.processObjectPropForm(vreq, editConfiguration);
|
||||||
} else {
|
} else {
|
||||||
this.initDataParameters(vreq, session);
|
this.processDataPropForm(vreq, session, editConfiguration);
|
||||||
this.processDataPropForm(vreq, editConfiguration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDataParameters(VitroRequest vreq, HttpSession session) {
|
|
||||||
dataHash = EditConfigurationUtils.getDataHash(vreq);
|
|
||||||
if( dataHash != null ){
|
|
||||||
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
|
|
||||||
}
|
|
||||||
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void initObjectParameters(VitroRequest vreq) {
|
private void initObjectParameters(VitroRequest vreq) {
|
||||||
|
@ -129,9 +120,22 @@ public class DefaultDeleteGenerator extends BaseEditConfigurationGenerator imple
|
||||||
//TODO: Check if null in case no object uri exists but this is still an object property
|
//TODO: Check if null in case no object uri exists but this is still an object property
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
|
||||||
//set data prop value, data prop key str,
|
private void processDataPropForm(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||||
|
if( dataHash != null ){
|
||||||
|
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
|
||||||
|
editConfiguration.setDatapropKey( dataHash );
|
||||||
|
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
|
||||||
|
if( dps != null ){
|
||||||
|
editConfiguration.addFormSpecificData("dataPropertyLexicalValue", dps.getData());
|
||||||
|
}else{
|
||||||
|
editConfiguration.addFormSpecificData("dataPropertyLexicalValue", "unknown value");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.debug("Did NOT find a datapropKey for hte data hash.");
|
||||||
|
editConfiguration.addFormSpecificData("dataPropertyLexicalValue", "unknown value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue