NIHVIVO-646 Using Javascript on page rather than hidden divs to pass information to the addAuthorsForm Javascript. Fix problems in DataPropertyComparator that were causing errors to be thrown on the page when no xsd datatype defined for an authorship rank.

This commit is contained in:
rjy7 2010-07-12 14:47:34 +00:00
parent 15ca4bae76
commit cc59f54794
2 changed files with 26 additions and 5 deletions

View file

@ -4,10 +4,21 @@ package edu.cornell.mannlib.vitro.webapp.beans;
import java.util.Comparator; import java.util.Comparator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.vocabulary.XSD; import com.hp.hpl.jena.vocabulary.XSD;
import edu.cornell.mannlib.vitro.webapp.search.controller.AutocompleteController;
/* This class is used to order authorships on the add author form. It should be removed in favor of using whatever
* method is used to order authorships on the publication profile page instead. I've implemented this due to
* time constraints.
*/
public class DataPropertyComparator implements Comparator<Individual> { public class DataPropertyComparator implements Comparator<Individual> {
private static final Log log = LogFactory.getLog(DataPropertyComparator.class);
private String dataPropertyUri = null; private String dataPropertyUri = null;
public DataPropertyComparator(String dataPropertyUri) { public DataPropertyComparator(String dataPropertyUri) {
@ -30,18 +41,28 @@ public class DataPropertyComparator implements Comparator<Individual> {
} else { } else {
String datatype = dps1.getDatatypeURI(); String datatype = dps1.getDatatypeURI();
if (datatype == null) {
datatype = dps2.getDatatypeURI();
}
if (datatype == null) {
log.warn("Can't compare data property statements: no datatype specified.");
// Perhaps we should throw an error here, but for now we need it to return 0
return 0;
}
if (datatype.equals(XSD.xint.toString())) { if (XSD.xint.toString().equals(datatype)) {
int i1 = Integer.valueOf(dps1.getData()); int i1 = Integer.valueOf(dps1.getData());
int i2 = Integer.valueOf(dps2.getData()); int i2 = Integer.valueOf(dps2.getData());
result = ((Integer) i1).compareTo(i2); result = ((Integer) i1).compareTo(i2);
} }
else if (datatype.equals(XSD.xstring.toString())) { else if (XSD.xstring.toString().equals(datatype)) {
result = dps1.getData().compareTo(dps2.getData()); result = dps1.getData().compareTo(dps2.getData());
} }
// Fill in other types here // Fill in other types here
else { else {
throw new ClassCastException("Unsupported datatype"); //throw new ClassCastException("Unsupported datatype");
log.warn("Can't compare data property statements: unsupported datatype.");
return 0;
} }
} }
return result; return result;

View file

@ -65,7 +65,7 @@ import freemarker.template.Configuration;
public class AutocompleteController extends FreeMarkerHttpServlet implements Searcher{ public class AutocompleteController extends FreeMarkerHttpServlet implements Searcher{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(AutocompleteController.class.getName()); private static final Log log = LogFactory.getLog(AutocompleteController.class);
private static String QUERY_PARAMETER_NAME = "term"; private static String QUERY_PARAMETER_NAME = "term";
private static String EXCLUDE_URI_PARAMETER_NAME = "excludeUri"; private static String EXCLUDE_URI_PARAMETER_NAME = "excludeUri";