diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/IdModelSelector.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/IdModelSelector.java index ae28fa7865..a1e4ff3ab2 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/IdModelSelector.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/IdModelSelector.java @@ -1,6 +1,7 @@ /* $This file is distributed under the terms of the license in LICENSE$ */ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration; +import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION; import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT; import javax.servlet.ServletContext; @@ -11,6 +12,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService; public class IdModelSelector implements ModelSelector { @@ -25,13 +28,26 @@ public IdModelSelector(String name) { @Override public Model getModel(HttpServletRequest request, ServletContext context) { - ModelMaker modelMaker = ModelAccess.on(context).getModelMaker(CONTENT); + ModelMaker modelMaker = ModelAccess.getInstance().getModelMaker(getRdfService()); VitroModelSource mSource = new VitroModelSource(modelMaker, context); return mSource.getModel(name); } + private WhichService getRdfService() { + return isConfigurationModel() ? CONFIGURATION : CONTENT; + } + + private boolean isConfigurationModel() { + return name.equals(VitroModelSource.ModelName.DISPLAY.toString()) || + name.equals(VitroModelSource.ModelName.DISPLAY_TBOX.toString()) || + name.equals(VitroModelSource.ModelName.DISPLAY_DISPLAY.toString()); + } + @Override public String getDefaultGraphUri() { + if (ModelNames.namesMap.containsKey(name)) { + return ModelNames.namesMap.get(name); + } return name; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java index 0d8d1d33e4..390bf667e5 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java @@ -40,6 +40,11 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.LimitRemovalsToLanguage; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; /** * This servlet will convert a request to an EditSubmission, @@ -107,7 +112,8 @@ protected ResponseValues processRequest(VitroRequest vreq) { configuration.addModelChangePreprocessor(new LimitRemovalsToLanguage(vreq.getLocale())); N3EditUtils.preprocessModels(changes, configuration, vreq); - ProcessRdfForm.applyChangesToWriteModel(changes, vreq.getRDFService(), writeModelSelector.getDefaultGraphUri(), N3EditUtils.getEditorUri(vreq)); + String graphUri = writeModelSelector.getDefaultGraphUri(); + ProcessRdfForm.applyChangesToWriteModel(changes, getRdfService(graphUri, writeModel), graphUri, N3EditUtils.getEditorUri(vreq)); //Here we are trying to get the entity to return to URL, //More involved processing for data property apparently @@ -119,6 +125,21 @@ protected ResponseValues processRequest(VitroRequest vreq) { return PostEditCleanupController.doPostEditRedirect(vreq, entityToReturnTo); } + private RDFService getRdfService(String graphUri, Model writeModel) { + RDFService configuration = ModelAccess.getInstance().getRDFService(WhichService.CONFIGURATION); + boolean isConfigurationGraph = false; + try { + isConfigurationGraph = configuration.getGraphURIs().contains(graphUri); + } catch (RDFServiceException e) { + log.error(e, e); + } + if (isConfigurationGraph) { + return new RDFServiceModel(writeModel); + } else { + return ModelAccess.getInstance().getRDFService(); + } + } + //In case of back button confusion //Currently returning an error message: //Later TODO: Per Brian Caruso's instructions, replicate