NIHVIVO-1341, NIHVIVO-1336 Implement strategies for handling missing linked individual in custom list views.

This commit is contained in:
rjy7 2010-12-21 20:30:13 +00:00
parent a03e7ccc50
commit 5ee3ecd89e
5 changed files with 48 additions and 8 deletions

View file

@ -56,6 +56,7 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod;
import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
@ -129,6 +130,7 @@ public class IndividualController extends FreemarkerHttpServlet {
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(ind));
body.put("url", new IndividualProfileUrlMethod());
body.put("localName", new IndividualLocalNameMethod());
String template = getIndividualTemplate(individual);

View file

@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -19,9 +18,8 @@ import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
@ -257,7 +255,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
Query query = null;
try {
query = QueryFactory.create(queryString);
query = QueryFactory.create(queryString, Syntax.syntaxARQ);
} catch(Throwable th){
log.error("could not create SPARQL query for query string " + th.getMessage());
log.error(queryString);

View file

@ -0,0 +1,36 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.web.functions;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import freemarker.core.Environment;
import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;
public class IndividualLocalNameMethod implements TemplateMethodModel {
@Override
public String exec(List args) throws TemplateModelException {
if (args.size() != 1) {
throw new TemplateModelException("Wrong number of arguments");
}
String uri = (String) args.get(0);
Environment env = Environment.getCurrentEnvironment();
HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
IndividualDao iDao = wdf.getIndividualDao();
Individual individual = iDao.getIndividualByURI(uri);
return individual.getLocalName();
}
}

View file

@ -111,7 +111,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
String configFilePath = getConfigFilePath(configFileName);
try {
File config = new File(configFilePath);
if (configFileName != DEFAULT_CONFIG_FILE && ! config.exists()) {
if ( ! isDefaultConfig(configFileName) && ! config.exists() ) {
log.warn("Can't find config file " + configFilePath + " for object property " + op.getURI() + "\n" +
". Using default config file instead.");
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE);
@ -124,7 +124,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
// What should we do here?
}
if ( ! configFileName.equals(DEFAULT_CONFIG_FILE) ) {
if ( ! isDefaultConfig(configFileName) ) {
String invalidConfigMessage = checkForInvalidConfig(vreq);
if ( StringUtils.isNotEmpty(invalidConfigMessage) ) {
log.warn("Invalid list view config for object property " + op.getURI() +
@ -136,6 +136,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
}
}
private boolean isDefaultConfig(String configFileName) {
return configFileName.equals(DEFAULT_CONFIG_FILE);
}
private String checkForInvalidConfig(VitroRequest vreq) {
String invalidConfigMessage = null;