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. */
|
||||
void processChanges(String editorUri, OntModel writeModel,
|
||||
void processChanges(String editorUri, Model writeModel,
|
||||
Model toBeAdded, Model toBeRetracted) throws Exception {
|
||||
Lock lock = null;
|
||||
log.debug("Model to be retracted is");
|
||||
|
@ -108,13 +108,17 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
|
|||
try {
|
||||
lock = writeModel.getLock();
|
||||
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.remove(toBeRetracted);
|
||||
} catch (Throwable t) {
|
||||
throw new Exception("Error while modifying model \n" + t.getMessage());
|
||||
} finally {
|
||||
writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri, false));
|
||||
if( writeModel instanceof OntModel){
|
||||
((OntModel)writeModel).getBaseModel().notifyEvent(new EditEvent(editorUri, false));
|
||||
}
|
||||
lock.leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +147,7 @@ public class PrimitiveRdfEdit extends VitroAjaxController {
|
|||
return models;
|
||||
}
|
||||
|
||||
private OntModel getWriteModel(VitroRequest vreq){
|
||||
private Model getWriteModel(VitroRequest vreq){
|
||||
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.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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.dao.DisplayVocabulary;
|
||||
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.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 {
|
||||
|
||||
|
@ -54,13 +63,10 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
|||
//Originally included in edit request dispatch controller but moved here due to
|
||||
//exceptions such as default add missing individual form
|
||||
void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
||||
//This used to get the model from the servlet context
|
||||
// Model model = (Model) getServletContext().getAttribute("jenaOntModel");
|
||||
//setup the model selectors for query, write and display models on editConfig
|
||||
setupModelSelectorsFromVitroRequest(vreq, editConfig);
|
||||
|
||||
//PROBLEM: this is returning the jenaOntModel
|
||||
// but we want the current abox model which might have
|
||||
// been set to the display model or something.
|
||||
Model model = vreq.getJenaOntModel();
|
||||
OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel");
|
||||
|
||||
if( editConfig.getSubjectUri() == null)
|
||||
editConfig.setSubjectUri( EditConfigurationUtils.getSubjectUri(vreq));
|
||||
|
@ -73,14 +79,42 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
|||
// editing existing object
|
||||
if( editConfig.getObject() == null)
|
||||
editConfig.setObject( EditConfigurationUtils.getObjectUri(vreq));
|
||||
editConfig.prepareForObjPropUpdate(model);
|
||||
editConfig.prepareForObjPropUpdate(queryModel);
|
||||
} else if( dataKey != null ) { // edit of a data prop statement
|
||||
//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{
|
||||
//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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,19 +101,10 @@ public class DefaultDeleteGenerator extends BaseEditConfigurationGenerator imple
|
|||
//not concerned about remainder, can move into default obj prop form if required
|
||||
this.initObjectParameters(vreq);
|
||||
this.processObjectPropForm(vreq, editConfiguration);
|
||||
} else {
|
||||
this.initDataParameters(vreq, session);
|
||||
this.processDataPropForm(vreq, editConfiguration);
|
||||
} else {
|
||||
this.processDataPropForm(vreq, session, 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||
//set data prop value, data prop key str,
|
||||
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||
|
||||
private void processDataPropForm(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||
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