diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java index f9322ad6c..bd34cfbd1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java @@ -93,8 +93,6 @@ public interface Individual extends ResourceBean, Comparable { void sortForDisplay(); JSONObject toJSON() throws JSONException; - - Object getField(String fieldName) throws NoSuchMethodException; Float getSearchBoost(); void setSearchBoost( Float boost ); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java index a09eaa7d0..4f0a0d889 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/IndividualImpl.java @@ -319,33 +319,6 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp JSONObject jsonObj = new JSONObject(this, INCLUDED_IN_JSON); return jsonObj; } - /** - * - * @param fieldName- expected to be the field name in the format - * @return - * @throws NoSuchMethodException - */ - public Object getField(String fieldName) throws NoSuchMethodException{ - if( fieldName == null || fieldName.length() == 0) return null; - - if( "name".equalsIgnoreCase(fieldName) ) - return getName(); - - //not one of the more common ones, try reflection - - //capitalize first letter - String methodName = "get" + fieldName.substring(0,1).toUpperCase() - + fieldName.substring(1,fieldName.length()); - - Class cls = this.getClass(); - try { - Method meth = cls.getMethod(methodName, (Class[]) null); - return meth.invoke(this,(Object[])null); - } catch (Exception e) { } - //should never get here - throw new NoSuchMethodException("Entity.getField() attempt to use a method called " - + methodName +"() for field " + fieldName + " but the method doesn't exist."); - } public int compareTo(Individual o2) { Collator collator = Collator.getInstance(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java index 3bac09894..1dd7d86e4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java @@ -289,12 +289,6 @@ public class ObjectProperty extends Property implements Comparable sortObjectPropertyStatementsForDisplay(ObjectProperty prop, List objPropStmtsList) { - if (objPropStmtsList==null) { - log.error("incoming object property statement list is null; returning null"); + public static List sortObjectPropertyStatementsForDisplay( + ObjectProperty prop, List objPropStmtsList) { + + if (objPropStmtsList == null) { + log.error("incoming object property statement list is null; " + + "returning null"); return null; } - if (objPropStmtsList.size()<2) { // no need to sort + if (objPropStmtsList.size() < 2) { // no need to sort return objPropStmtsList; } - String tmpDirection = prop.getDomainEntitySortDirection(); //valid values are "desc" and "asc", anything else will default to ascending - final boolean direction = !"desc".equalsIgnoreCase(tmpDirection); + + String tmpDirection = prop.getDomainEntitySortDirection(); + // Valid values are "desc" and "asc"; + // anything else will default to ascending. + final boolean ascending = !"desc".equalsIgnoreCase(tmpDirection); - String objIndivSortPropURI=prop.getObjectIndividualSortPropertyURI(); - if (prop.getObjectIndividualSortPropertyURI() == null || prop.getObjectIndividualSortPropertyURI().length()==0) { - String tmpField = prop.getDomainEntitySortField(); - log.debug("objectIndividualSortPropertyURI is null or blank so sorting by field "+tmpField); - if( tmpField == null || tmpField.length() == 0) { - tmpField = "name"; - } - final String field = tmpField; + String objIndivSortPropURI = prop.getObjectIndividualSortPropertyURI(); + if (prop.getObjectIndividualSortPropertyURI() == null + || prop.getObjectIndividualSortPropertyURI().length() == 0) { + log.debug("objectIndividualSortPropertyURI is null or blank " + + "so sorting by name "); Comparator fieldComp = new Comparator() { - final String cField= field; - final boolean cAsc = direction; - + public final int compare(Object o1, Object o2) { - ObjectPropertyStatement e2e1= (ObjectPropertyStatement)o1, e2e2=(ObjectPropertyStatement)o2; + ObjectPropertyStatement e2e1 = (ObjectPropertyStatement) o1, + e2e2 = (ObjectPropertyStatement) o2; Individual e1 , e2; e1 = e2e1 != null ? e2e1.getObject():null; e2 = e2e2 != null ? e2e2.getObject():null; Object val1 = null, val2 = null; if( e1 != null ) { - try { - val1 = e1.getField(cField); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } + val1 = e1.getName(); } else { - log.debug( "PropertyWebapp.sortObjectPropertiesForDisplay() passed object property statement with no range entity."); + log.debug( "PropertyWebapp.sortObjectPropertiesForDisplay() " + + "passed object property statement with no range entity."); } if( e2 != null ) { - try { - val2 = e2.getField(cField); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } + val2 = e2.getName(); } else { - log.debug( "PropertyWebapp.sortObjectPropertyStatementsForDisplay passed object property statement with no range entity."); + log.debug( "PropertyWebapp.sortObjectPropertyStatementsForDisplay " + + "passed object property statement with no range entity."); } int rv = 0; try { if( val1 instanceof String ) { - - if (val1 == null && val2 == null) { - rv = 0; - } else if (val1 == null) { - rv = 1; - } else if (val2 == null) { + if (val2 == null) { rv = -1; } else { - Collator collator = Collator.getInstance(); - rv = collator.compare( ((String)val1) , ((String)val2) ); - //rv = ((String)val1).compareTo((String)val2); + rv = collator.compare( ((String)val1) , ((String)val2) ); } - } else if( val1 instanceof Date ) { DateTime dt1 = new DateTime((Date)val1); DateTime dt2 = new DateTime((Date)val2); @@ -473,7 +447,7 @@ public class ObjectProperty extends Property implements Comparable - Optional: sort related individuals by
- (default is sort by name)

- " /> - - - - - +   Optional: sort direction
(blank for ascending, "desc" for descending)

@@ -276,13 +269,7 @@ - Optional: sort related object individuals of inverse property by
- (default is sort by name)

- " /> - - - - +   Optional: inverse sort direction