diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java index 55c96503..832b88f7 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/valueobjects/Grant.java @@ -1,7 +1,10 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.visualization.freemarker.valueobjects; +import org.joda.time.DateTime; + import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants; +import edu.cornell.mannlib.vitro.webapp.visualization.freemarker.visutils.UtilityFunctions; /** * @author bkoniden @@ -37,42 +40,32 @@ public class Grant extends Individual { public void setGrantLabel(String grantLabel) { this.setIndividualLabel(grantLabel); } + + /** - * This method will be called when there is no usable core:year value found - * for the bibo:Document. It will first check & parse core:yearMonth failing - * which it will try core:date + * This method will be called to get the inferred start year for the grant. + * The 3 choices, in order, are, + * 1. parsed year from xs:DateTime object saved in core:dateTimeValue + * 2. core:year which was property used in vivo 1.1 ontology + * 3. Default Grant Start Year * @return */ public String getParsedGrantStartYear() { - - /* - * We are assuming that core:yearMonth has "YYYY-MM-DD" format. This is based - * off of http://www.w3.org/TR/xmlschema-2/#gYearMonth , which is what - * core:yearMonth points to internally. - * */ - if (grantStartYearMonth != null - && grantStartYearMonth.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT - && isValidPublicationYear(grantStartYearMonth.substring( - 0, - VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) { - - return grantStartYearMonth.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT); - + + if (grantStartDate != null) { + + DateTime validParsedDateTimeObject = UtilityFunctions + .getValidParsedDateTimeObject(grantStartDate); + + if (validParsedDateTimeObject != null) { + return String.valueOf(validParsedDateTimeObject.getYear()); + } else { + return VOConstants.DEFAULT_GRANT_YEAR; + } + } else { + return VOConstants.DEFAULT_GRANT_YEAR; } - - if (grantStartDate != null - && grantStartDate.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT - && isValidPublicationYear(grantStartDate - .substring(0, - VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) { - - return grantStartDate.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT); - } - - /* - * If all else fails return default unknown year identifier - * */ - return VOConstants.DEFAULT_GRANT_YEAR; + } public String getGrantStartYear() { @@ -135,4 +128,42 @@ public class Grant extends Individual { return false; } +// /** +// * This method will be called when there is no usable core:year value found +// * for the core:Grant. It will first check & parse core:yearMonth failing +// * which it will try core:date +// * @return +// */ +// public String getParsedGrantStartYear() { +// +// /* +// * We are assuming that core:yearMonth has "YYYY-MM-DD" format. This is based +// * off of http://www.w3.org/TR/xmlschema-2/#gYearMonth , which is what +// * core:yearMonth points to internally. +// * */ +// if (grantStartYearMonth != null +// && grantStartYearMonth.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT +// && isValidPublicationYear(grantStartYearMonth.substring( +// 0, +// VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) { +// +// return grantStartYearMonth.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT); +// +// } +// +// if (grantStartDate != null +// && grantStartDate.length() >= VOConstants.NUM_CHARS_IN_YEAR_FORMAT +// && isValidPublicationYear(grantStartDate +// .substring(0, +// VOConstants.NUM_CHARS_IN_YEAR_FORMAT))) { +// +// return grantStartDate.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT); +// } +// +// /* +// * If all else fails return default unknown year identifier +// * */ +// return VOConstants.DEFAULT_GRANT_YEAR; +// } + } diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java index 4c9ece4a..87b45674 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/freemarker/visutils/UtilityFunctions.java @@ -238,12 +238,7 @@ public class UtilityFunctions { * changes all throughout the codebase. * 3. We are asking for a grant year & we should get a proper one or NOT at all. * */ - String grantYear; - if (curr.getGrantStartYear() != null) { - grantYear = curr.getGrantStartYear(); - } else { - grantYear = curr.getParsedGrantStartYear(); - } + String grantYear = curr.getParsedGrantStartYear(); if (yearToGrantCount.containsKey(grantYear)) { yearToGrantCount.put(grantYear,