From cc59f54794c20083d5c337bbbe7440759d27b39f Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 12 Jul 2010 14:47:34 +0000 Subject: [PATCH] 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. --- .../webapp/beans/DataPropertyComparator.java | 29 ++++++++++++++++--- .../controller/AutocompleteController.java | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java index de7a5b280..ac25af2f1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java @@ -4,10 +4,21 @@ package edu.cornell.mannlib.vitro.webapp.beans; import java.util.Comparator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + 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 { + private static final Log log = LogFactory.getLog(DataPropertyComparator.class); + private String dataPropertyUri = null; public DataPropertyComparator(String dataPropertyUri) { @@ -30,18 +41,28 @@ public class DataPropertyComparator implements Comparator { } else { String datatype = dps1.getDatatypeURI(); - - if (datatype.equals(XSD.xint.toString())) { + 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 (XSD.xint.toString().equals(datatype)) { int i1 = Integer.valueOf(dps1.getData()); int i2 = Integer.valueOf(dps2.getData()); 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()); } // Fill in other types here 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; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java index 8d96fda8b..930b18a56 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java @@ -65,7 +65,7 @@ import freemarker.template.Configuration; public class AutocompleteController extends FreeMarkerHttpServlet implements Searcher{ 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 EXCLUDE_URI_PARAMETER_NAME = "excludeUri";