Continue to reduce the Model Madness!
Add OntModelCache to the top of the stack of RDF data structures. Add DataStructuresProvider to the bottom of the stack. Redesign ModelAccess method signatures. Create the ShowSources page. Remove RequestModelsPrep, except for setting the Collator. Reduce the complexity of ContentModelsSetup and ConfigurationModelsSetup. VIVO-225 VIVO-819 VIVO-820 VIVO-821 VIVO-823 VIVO-832
This commit is contained in:
parent
c9362db3c1
commit
78c8f102f8
171 changed files with 4196 additions and 2826 deletions
|
@ -0,0 +1,122 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption.ASSERTIONS_AND_INFERENCES;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
|
||||
/**
|
||||
* A mock instance of ContextModelAccess for use in unit tests.
|
||||
*
|
||||
* I have only implemented the methods that I needed for my tests. Feel free to
|
||||
* implement the rest, as needed.
|
||||
*/
|
||||
public class ContextModelAccessStub implements ContextModelAccess {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<ReasoningOption, WebappDaoFactory> wadfMap = new HashMap<>();
|
||||
|
||||
public void setWebappDaoFactory(WebappDaoFactory wadf) {
|
||||
setWebappDaoFactory(wadf, ASSERTIONS_AND_INFERENCES);
|
||||
}
|
||||
|
||||
public void setWebappDaoFactory(WebappDaoFactory wadf,
|
||||
ReasoningOption option) {
|
||||
wadfMap.put(option, wadf);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory() {
|
||||
return wadfMap.get(ASSERTIONS_AND_INFERENCES);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public RDFService getRDFService() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getRDFService() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDFService getRDFService(WhichService which) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getRDFService() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset getDataset() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getDataset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset getDataset(WhichService which) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getDataset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelMaker getModelMaker() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getModelMaker() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelMaker getModelMaker(WhichService which) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getModelMaker() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModel() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel(String name) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModel() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModelSelector getOntModelSelector() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModelSelector() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModelSelector getOntModelSelector(ReasoningOption option) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModelSelector() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory(ReasoningOption option) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getWebappDaoFactory() not implemented.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ModelAccessFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.RequestModelAccess;
|
||||
|
||||
/**
|
||||
* A mock instance of ModelAccessFactory for use in unit tests.
|
||||
*
|
||||
* I have only implemented the methods that I needed for my tests. Feel free to
|
||||
* implement the rest, as needed.
|
||||
*/
|
||||
public class ModelAccessFactoryStub extends ModelAccessFactory {
|
||||
private final ContextModelAccessStub contextMA;
|
||||
private final RequestModelAccessStub requestMA;
|
||||
|
||||
public ModelAccessFactoryStub() {
|
||||
try {
|
||||
Field factoryField = ModelAccess.class.getDeclaredField("factory");
|
||||
factoryField.setAccessible(true);
|
||||
factoryField.set(null, this);
|
||||
} catch (NoSuchFieldException | SecurityException
|
||||
| IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(
|
||||
"Failed to create the ModelAccessFactoryStub", e);
|
||||
}
|
||||
|
||||
contextMA = new ContextModelAccessStub();
|
||||
requestMA = new RequestModelAccessStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextModelAccess buildContextModelAccess(ServletContext ctx) {
|
||||
return contextMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestModelAccess buildRequestModelAccess(HttpServletRequest req) {
|
||||
return requestMA;
|
||||
}
|
||||
|
||||
public ContextModelAccessStub get(ServletContext ctx) {
|
||||
return contextMA;
|
||||
}
|
||||
|
||||
public RequestModelAccessStub get(HttpServletRequest req) {
|
||||
return requestMA;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.DatasetOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.OntModelSelectorOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.RdfServiceOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WebappDaoFactoryOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.RequestModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.OntModelKey;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.RDFServiceKey;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.WebappDaoFactoryKey;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
|
||||
/**
|
||||
* A mock instance of RequestModelAccess for use in unit tests.
|
||||
*
|
||||
* I have only implemented the methods that I needed for my tests. Feel free to
|
||||
* implement the rest, as needed.
|
||||
*/
|
||||
public class RequestModelAccessStub implements RequestModelAccess {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<RDFServiceKey, RDFService> rdfServiceMap = new HashMap<>();
|
||||
|
||||
public void setRDFService(RDFService rdfService,
|
||||
RdfServiceOption... options) {
|
||||
rdfServiceMap.put(new RDFServiceKey(options), rdfService);
|
||||
}
|
||||
|
||||
private final Map<OntModelKey, OntModel> ontModelMap = new HashMap<>();
|
||||
|
||||
public void setOntModel(OntModel model, String name) {
|
||||
ontModelMap.put(new OntModelKey(name), model);
|
||||
}
|
||||
|
||||
private final Map<WebappDaoFactoryKey, WebappDaoFactory> wadfMap = new HashMap<>();
|
||||
|
||||
public void setWebappDaoFactory(WebappDaoFactory wadf,
|
||||
WebappDaoFactoryOption... options) {
|
||||
wadfMap.put(new WebappDaoFactoryKey(options), wadf);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public RDFService getRDFService(RdfServiceOption... options) {
|
||||
return rdfServiceMap.get(new RDFServiceKey(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel(LanguageOption... options) {
|
||||
return getOntModel(ModelNames.FULL_UNION, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel(String name, LanguageOption... options) {
|
||||
return ontModelMap.get(new OntModelKey(name, options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory(
|
||||
WebappDaoFactoryOption... options) {
|
||||
return wadfMap.get(new WebappDaoFactoryKey(options));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Dataset getDataset(DatasetOption... options) {
|
||||
throw new RuntimeException(
|
||||
"RequestModelAccessStub.getDataset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModelSelector getOntModelSelector(
|
||||
OntModelSelectorOption... options) {
|
||||
throw new RuntimeException(
|
||||
"RequestModelAccessStub.getOntModelSelector() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
throw new RuntimeException(
|
||||
"RequestModelAccessStub.close() not implemented.");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue