NIHVIVO-1731

1) Modified body foe getParsedGrantStartYear(). -- Previously, it used custom logic for parsing the year value of a Date string. Now, it uses jodatime library's utilities to parse year values.
2) Removed redundant code from UtilityFunctions.java -- pertaining to grantUtility functions.
This commit is contained in:
bkoniden 2011-01-27 19:15:36 +00:00
parent ce793e0d49
commit 9c72c0af02
2 changed files with 63 additions and 37 deletions

View file

@ -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))) {
if (grantStartDate != null) {
return grantStartYearMonth.substring(0, VOConstants.NUM_CHARS_IN_YEAR_FORMAT);
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;
// }
}

View file

@ -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,