Study study = findStudy(tb1StudyId);
if ( study == null ) {
warn("No such study (TB1 accession): " + tb1StudyId);
return;
}
Citation citationStub = study.getCitation();
Citation citation = null;
if ( citationStub != null ) {
warn("Study "+tb1StudyId+" already associated with a citation "+citationStub.getId());
// In general, citation stubs already exist for each study. However, these
// stubs are all of type ArticleCitation, which means that, in the case of
// BookCitations (for example) we'll get a class cast exception when we try
// to cast the citation to a book in order to set the editors.
//getCitationService().deleteCitation(citationStub);
//citation = createCitation(fields[0]);
citation = citationStub;
}
else {
warn("No citation stub association with study (TB1 accession) " + tb1StudyId);
citation = createCitation(fields[0]);
}
if ( citation == null ) {
warn("No citation was instantiated, skipping this record (TB1 accession) "+tb1StudyId);
return;
}
for ( int i = 0; i < fields.length; i++ ) {
if ( ! TreebaseUtil.isEmpty(fields[i]) ) {
switch(i) {
case 0: citation.setCitationType(fields[i]); break;
case 1: setAuthors(citation,fields[i],personHome,false); break;
case 2: citation.setPublishYear(Integer.parseInt(fields[i])); break;
case 3: if ( citation instanceof BookCitation ) {
((BookCitation)citation).setBookTitle(fields[i]);
citation.setTitle(fields[i]);
} else {
citation.setTitle(fields[i]);
} break;
case 4: setAuthors(citation,fields[i],personHome,true); break;
case 5: if ( citation instanceof ArticleCitation ) {
((ArticleCitation)citation).setJournal(fields[i]);
warn("Setting journal name "+fields[i]);
} else {
warn("Setting book title "+fields[i]);
((BookCitation)citation).setBookTitle(fields[i]);
} break;
case 6: if ( citation instanceof BookCitation ) {
((BookCitation)citation).setCity(fields[i]);
} else {
warn("Record has an entry for city, yet it's not a book (TB1 accession) "+tb1StudyId);
} break;
case 7: if ( citation instanceof BookCitation ) {
((BookCitation)citation).setPublisher(fields[i]);
} else {
warn("Record has an entry for publisher, yet it's not a book (TB1 accession) "+tb1StudyId);
} break;
case 8: if ( citation instanceof ArticleCitation ) {
((ArticleCitation)citation).setVolume(fields[i]);
} else {
warn("Record has an entry for volume, yet it's not an article (TB1 accession) "+tb1StudyId);
} break;
case 10: if ( citation instanceof ArticleCitation ) {
((ArticleCitation)citation).setIssue(fields[i]);
} else {
warn("Record has an entry for issue, yet it's not an article (TB1 accession)"+tb1StudyId);
} break;
case 11: citation.setPages(fields[i]); break;
case 15: if ( fields[i].equals("in press") ) {
citation.setCitationStatusDescription(CitationStatus.INPRESS);
}
case 16: citation.setKeywords(fields[i]); break;
case 17: citation.setAbstract(checkAbstractLength(fields[i])); break;
case 18: citation.setStudy(study); break;
case 19: citation.setURL(fields[i]); break;
case 20: citation.setDoi(fields[i]); break;
default: warn("Empty field expected, found: " + fields[i] + " for line: " + /*was: line */fields.toString()); break;
}
}
}
warn("Storing citation "+citation.getId());
warn(citation.getAuthorsCitationStyleWithoutHtml());
if ( ! testMode ) {
study.setCitation(citation);
getStudyService().update(study);
Long id = study.getCitation().getId();
warn("Stored citation at ID " + id);