Skip to content

Commit

Permalink
Provide correct RdfService ang graph uri on apply changes to write model
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg authored and chenejac committed May 2, 2024
1 parent 91ac747 commit d910dd3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d910dd3

Please sign in to comment.