From: <rv...@us...> - 2010-03-15 01:11:50
|
Revision: 575 http://treebase.svn.sourceforge.net/treebase/?rev=575&view=rev Author: rvos Date: 2010-03-15 01:11:43 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Added getAnnotations() for nexml and rdf serialization. Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java 2010-03-15 01:08:05 UTC (rev 574) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java 2010-03-15 01:11:43 UTC (rev 575) @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.List; import javax.persistence.AttributeOverride; @@ -23,12 +24,18 @@ import javax.persistence.Table; import javax.persistence.Transient; +import org.hibernate.Session; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.IndexColumn; import org.springframework.beans.BeanUtils; +import org.cipres.treebase.Constants; +import org.cipres.treebase.ContextManager; import org.cipres.treebase.domain.AbstractPersistedObject; +import org.cipres.treebase.domain.Annotation; import org.cipres.treebase.domain.TBPersistable; import org.cipres.treebase.domain.admin.Person; @@ -302,15 +309,15 @@ /** * Get an ordered list of authors. - * + * @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "studyCache") * @return - */ + */ @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST}) @JoinTable(name = "CITATION_AUTHOR", joinColumns = {@JoinColumn(name = "CITATION_ID")}) - @IndexColumn(name = "AUTHOR_ORDER") - @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "studyCache") + @IndexColumn(name = "AUTHOR_ORDER") + @Fetch(FetchMode.JOIN) public List<Person> getAuthors() { - return mAuthors; + return mAuthors; // The fetch annotation prevents org.hibernate.LazyInitializationException } /** @@ -492,6 +499,25 @@ } @Transient + private String getAuthorsAsString() { + StringBuilder authorsCitationStyle = new StringBuilder(); + List<Person> authors = getAuthors(); + int size = authors.size(); + if (size > 0) { + for ( int i = 0; i < size; i++ ) { + authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); + if ( size > 1 && i == size - 2 ) { + authorsCitationStyle.append(", & "); + } + else if (size > 1 && i < size - 2) { + authorsCitationStyle.append(", "); + } + } + } + return authorsCitationStyle.toString(); + } + + @Transient public String getAuthorsAsBibtex() { return catPersonsBibtex(getAuthors()); } @@ -647,5 +673,56 @@ protected void getDetailedPublicationInformation(StringBuilder pBuilder, boolean pGenerateHtml) { } + + @Transient + public List<Annotation> getAnnotations() { + List<Annotation> annotations = super.getAnnotations(); + annotations.add(new Annotation(Constants.DCTermsURI,"dcterms:bibliographicCitation",getAuthorsCitationStyleWithoutHtml())); + annotations.add(new Annotation(Constants.DCURI,"dc:title",getTitle())); + annotations.add(new Annotation(Constants.DCURI,"dc:creator",getAuthorsAsString())); + for ( Person person : getAuthors() ) { + String personName = person.getFullNameCitationStyle(); + annotations.add(new Annotation(Constants.DCURI,"dc:contributor",personName)); + } + try { + if ( null != getPublishYear() ) { + annotations.add(new Annotation(Constants.PrismURI,"prism:publicationDate",getPublishYear().toString())); + } + if ( null != getDoi() ) { + annotations.add(new Annotation(Constants.PrismURI,"prism:doi",getDoi())); + } + if ( null != getPages() ) { + String[] pages = getPages().split("\\-"); + if ( pages.length == 2 ) { + annotations.add(new Annotation(Constants.PrismURI,"prism:startingPage",pages[0])); + annotations.add(new Annotation(Constants.PrismURI,"prism:endingPage",pages[1])); + annotations.add(new Annotation(Constants.PrismURI,"prism:pageRange",getPages())); + } + } + if ( null != getKeywords() ) { + String[] keywords = getKeywords().split(", "); + for ( int i = 0; i < keywords.length; i++ ) { + annotations.add(new Annotation(Constants.DCURI,"dc:subject",keywords[i])); + } + } + if ( this instanceof ArticleCitation ) { + ArticleCitation ac = (ArticleCitation)this; + String journal = ac.getJournal(); + if ( null != journal ) { + annotations.add(new Annotation(Constants.PrismURI,"prism:publicationName",journal)); + annotations.add(new Annotation(Constants.DCURI,"dc:publisher",journal)); + } + if ( null != ac.getVolume() ) { + annotations.add(new Annotation(Constants.PrismURI,"prism:volume",ac.getVolume())); + } + if ( null != ac.getIssue() ) { + annotations.add(new Annotation(Constants.PrismURI,"prism:number",ac.getIssue())); + } + } + } catch ( Exception e ) { + e.printStackTrace(); + } + return annotations; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-06-01 17:11:24
|
Revision: 701 http://treebase.svn.sourceforge.net/treebase/?rev=701&view=rev Author: rvos Date: 2010-06-01 17:11:18 +0000 (Tue, 01 Jun 2010) Log Message: ----------- Wrapped author name concatenation in try/catch block Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java 2010-06-01 16:28:03 UTC (rev 700) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java 2010-06-01 17:11:18 UTC (rev 701) @@ -475,26 +475,31 @@ public String getAuthorsCitationStyleWithoutHtml() { StringBuilder authorsCitationStyle = new StringBuilder(); - List<Person> authors = getAuthors(); - int size = authors.size(); - - if (size > 0) { - - for (int i = 0; i < size; i++) { - - authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); - - if (size > 1 && i == size - 2) { - authorsCitationStyle.append(", & "); - } else if (size > 1 && i < size - 2) { - authorsCitationStyle.append(", "); + try { + List<Person> authors = getAuthors(); + int size = authors.size(); + + if (size > 0) { + + for (int i = 0; i < size; i++) { + + authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); + + if (size > 1 && i == size - 2) { + authorsCitationStyle.append(", & "); + } else if (size > 1 && i < size - 2) { + authorsCitationStyle.append(", "); + } } + } - + + authorsCitationStyle.append(" ").append(getPublishYear()); + getDetailedPublicationInformation(authorsCitationStyle, false); } - - authorsCitationStyle.append(" ").append(getPublishYear()); - getDetailedPublicationInformation(authorsCitationStyle, false); + catch ( Exception e ) { + e.printStackTrace(); + } return authorsCitationStyle.toString(); } @@ -525,65 +530,70 @@ @Transient public String getRisReference () { StringBuilder ris = new StringBuilder(), sub = new StringBuilder(); - String citationType = this.getRealCitationType(), cls = "\n"; - boolean isArticle = false, isBook = false, isInBook = false; - if ( citationType.equals(ArticleCitation.CITATION_TYPE_ARTICLE) ) { - ris.append("TY - JOUR\n"); - sub.append("JF - ").append(appendMe(((ArticleCitation)this).getJournal())).append(cls); - sub.append("VL - ").append(appendMe(((ArticleCitation)this).getVolume())).append(cls); - sub.append("IS - ").append(appendMe(((ArticleCitation)this).getIssue())).append(cls); - isArticle = true; - } - else if ( citationType.equals(BookCitation.CITATION_TYPE_BOOK) ) { - ris.append("TY - BOOK\n"); - isBook = true; - } - else if ( citationType.equals(InBookCitation.CITATION_TYPE_BOOKSECTION) ) { - ris.append("TY - CHAP\n"); - sub.append("TI - ").append(appendMe(((InBookCitation)this).getBookTitle())).append(cls); - isInBook = true; - } - if ( isBook || isInBook) { - sub.append("SN - ISBN ").append(appendMe(((BookCitation)this).getISBN())).append(cls); - sub.append("PB - ").append(appendMe(((BookCitation)this).getPublisher())).append(cls); - sub.append("CY - ").append(appendMe(((BookCitation)this).getCity())).append(cls); - catPersonsRis(sub,"ED - ",((BookCitation)this).getEditors()); - } - if ( isInBook || isArticle ) { - String pages = getPages(); - if ( pages != null && pages.matches("^\\d+-\\d+$") ) { - String[] pageRange = pages.split("-"); - sub.append("SP - ").append(pageRange[0]).append(cls); - sub.append("EP - ").append(pageRange[1]).append(cls); + try { + String citationType = this.getRealCitationType(), cls = "\n"; + boolean isArticle = false, isBook = false, isInBook = false; + if ( citationType.equals(ArticleCitation.CITATION_TYPE_ARTICLE) ) { + ris.append("TY - JOUR\n"); + sub.append("JF - ").append(appendMe(((ArticleCitation)this).getJournal())).append(cls); + sub.append("VL - ").append(appendMe(((ArticleCitation)this).getVolume())).append(cls); + sub.append("IS - ").append(appendMe(((ArticleCitation)this).getIssue())).append(cls); + isArticle = true; } - } - ris.append("ID - ").append(getId()).append(cls); - catPersonsRis(ris,"AU - ",getAuthors()); - ris.append("T1 - ").append(appendMe(getTitle())).append(cls); - ris.append("PY - ").append(appendMe(getPublishYear())).append(cls); - String keyWords = getKeywords(); - if ( keyWords != null ) { - String[] words = keyWords.split(",\\s*"); - for ( int i = 0; i < words.length; i++ ) { - ris.append("KW - ").append(appendMe(words[i])).append(cls); + else if ( citationType.equals(BookCitation.CITATION_TYPE_BOOK) ) { + ris.append("TY - BOOK\n"); + isBook = true; + } + else if ( citationType.equals(InBookCitation.CITATION_TYPE_BOOKSECTION) ) { + ris.append("TY - CHAP\n"); + sub.append("TI - ").append(appendMe(((InBookCitation)this).getBookTitle())).append(cls); + isInBook = true; + } + if ( isBook || isInBook) { + sub.append("SN - ISBN ").append(appendMe(((BookCitation)this).getISBN())).append(cls); + sub.append("PB - ").append(appendMe(((BookCitation)this).getPublisher())).append(cls); + sub.append("CY - ").append(appendMe(((BookCitation)this).getCity())).append(cls); + catPersonsRis(sub,"ED - ",((BookCitation)this).getEditors()); } + if ( isInBook || isArticle ) { + String pages = getPages(); + if ( pages != null && pages.matches("^\\d+-\\d+$") ) { + String[] pageRange = pages.split("-"); + sub.append("SP - ").append(pageRange[0]).append(cls); + sub.append("EP - ").append(pageRange[1]).append(cls); + } + } + ris.append("ID - ").append(getId()).append(cls); + catPersonsRis(ris,"AU - ",getAuthors()); + ris.append("T1 - ").append(appendMe(getTitle())).append(cls); + ris.append("PY - ").append(appendMe(getPublishYear())).append(cls); + String keyWords = getKeywords(); + if ( keyWords != null ) { + String[] words = keyWords.split(",\\s*"); + for ( int i = 0; i < words.length; i++ ) { + ris.append("KW - ").append(appendMe(words[i])).append(cls); + } + } + String url = getURL(), doi = getDoi(), pmid = getPMID(); + String theUrl = null; + if ( url != null && ! url.equals("http://") ) { + theUrl = url; + } + else if ( doi != null ) { + theUrl = "http://dx.doi.org/" + doi; + } + else if ( pmid != null ) { + theUrl = "http://pmid.us/" + pmid; + } + ris.append("UR - ").append(appendMe(theUrl)).append(cls); + ris.append("N2 - ").append(appendMe(getAbstract())).append(cls); + ris.append("L3 - ").append(appendMe(getDoi())).append(cls); + ris.append(sub); + ris.append("ER - ").append(cls); } - String url = getURL(), doi = getDoi(), pmid = getPMID(); - String theUrl = null; - if ( url != null && ! url.equals("http://") ) { - theUrl = url; + catch ( Exception e ) { + e.printStackTrace(); } - else if ( doi != null ) { - theUrl = "http://dx.doi.org/" + doi; - } - else if ( pmid != null ) { - theUrl = "http://pmid.us/" + pmid; - } - ris.append("UR - ").append(appendMe(theUrl)).append(cls); - ris.append("N2 - ").append(appendMe(getAbstract())).append(cls); - ris.append("L3 - ").append(appendMe(getDoi())).append(cls); - ris.append(sub); - ris.append("ER - ").append(cls); return ris.toString(); } @@ -603,44 +613,49 @@ @Transient public String getBibtexReference () { StringBuilder bib = new StringBuilder(), sub = new StringBuilder(); - String citationType = this.getRealCitationType(), cls = "},"; - boolean isArticle = false, isBook = false, isInBook = false; - if ( citationType.equals(ArticleCitation.CITATION_TYPE_ARTICLE) ) { - bib.append("@ARTICLE{"); - sub.append("\n\t journal = {").append(appendMe(((ArticleCitation)this).getJournal())).append(cls); - sub.append("\n\t volume = {").append(appendMe(((ArticleCitation)this).getVolume())).append(cls); - sub.append("\n\t number = {").append(appendMe(((ArticleCitation)this).getIssue())).append(cls); - isArticle = true; + try { + String citationType = this.getRealCitationType(), cls = "},"; + boolean isArticle = false, isBook = false, isInBook = false; + if ( citationType.equals(ArticleCitation.CITATION_TYPE_ARTICLE) ) { + bib.append("@ARTICLE{"); + sub.append("\n\t journal = {").append(appendMe(((ArticleCitation)this).getJournal())).append(cls); + sub.append("\n\t volume = {").append(appendMe(((ArticleCitation)this).getVolume())).append(cls); + sub.append("\n\t number = {").append(appendMe(((ArticleCitation)this).getIssue())).append(cls); + isArticle = true; + } + else if ( citationType.equals(BookCitation.CITATION_TYPE_BOOK) ) { + bib.append("@BOOK{"); + isBook = true; + } + else if ( citationType.equals(InBookCitation.CITATION_TYPE_BOOKSECTION) ) { + bib.append("@INCOLLECTION{"); + sub.append("\n\t booktitle = {").append(appendMe(((InBookCitation)this).getBookTitle())).append(cls); + isInBook = true; + } + if ( isBook || isInBook) { + sub.append("\n\t isbn = {").append(appendMe(((BookCitation)this).getISBN())).append(cls); + sub.append("\n\t publisher = {").append(appendMe(((BookCitation)this).getPublisher())).append(cls); + sub.append("\n\t address = {").append(appendMe(((BookCitation)this).getCity())).append(cls); + sub.append("\n\t editor = {").append(appendMe(catPersonsBibtex(((BookCitation)this).getEditors()))).append(cls); + } + if ( isInBook || isArticle ) { + sub.append("\n\t pages = {").append(appendMe(getPages()).replaceFirst("\\-", "--")).append(cls); + } + bib.append("TreeBASE2Ref").append(getId()).append(","); + bib.append("\n\t author = {").append(appendMe(catPersonsBibtex(getAuthors()))).append(cls); + bib.append("\n\t title = {").append(appendMe(getTitle())).append(cls); + bib.append("\n\t year = {").append(appendMe(getPublishYear())).append(cls); + bib.append("\n\t keywords = {").append(appendMe(getKeywords())).append(cls); + bib.append("\n\t doi = {").append(appendMe(getDoi())).append(cls); + bib.append("\n\t url = {").append(appendMe(getURL())).append(cls); + bib.append("\n\t pmid = {").append(appendMe(getPMID())).append(cls); + bib.append(sub); + bib.append("\n\t abstract = {").append(appendMe(getAbstract())).append("}"); + bib.append("\n}"); } - else if ( citationType.equals(BookCitation.CITATION_TYPE_BOOK) ) { - bib.append("@BOOK{"); - isBook = true; + catch ( Exception e ) { + e.printStackTrace(); } - else if ( citationType.equals(InBookCitation.CITATION_TYPE_BOOKSECTION) ) { - bib.append("@INCOLLECTION{"); - sub.append("\n\t booktitle = {").append(appendMe(((InBookCitation)this).getBookTitle())).append(cls); - isInBook = true; - } - if ( isBook || isInBook) { - sub.append("\n\t isbn = {").append(appendMe(((BookCitation)this).getISBN())).append(cls); - sub.append("\n\t publisher = {").append(appendMe(((BookCitation)this).getPublisher())).append(cls); - sub.append("\n\t address = {").append(appendMe(((BookCitation)this).getCity())).append(cls); - sub.append("\n\t editor = {").append(appendMe(catPersonsBibtex(((BookCitation)this).getEditors()))).append(cls); - } - if ( isInBook || isArticle ) { - sub.append("\n\t pages = {").append(appendMe(getPages()).replaceFirst("\\-", "--")).append(cls); - } - bib.append("TreeBASE2Ref").append(getId()).append(","); - bib.append("\n\t author = {").append(appendMe(catPersonsBibtex(getAuthors()))).append(cls); - bib.append("\n\t title = {").append(appendMe(getTitle())).append(cls); - bib.append("\n\t year = {").append(appendMe(getPublishYear())).append(cls); - bib.append("\n\t keywords = {").append(appendMe(getKeywords())).append(cls); - bib.append("\n\t doi = {").append(appendMe(getDoi())).append(cls); - bib.append("\n\t url = {").append(appendMe(getURL())).append(cls); - bib.append("\n\t pmid = {").append(appendMe(getPMID())).append(cls); - bib.append(sub); - bib.append("\n\t abstract = {").append(appendMe(getAbstract())).append("}"); - bib.append("\n}"); return bib.toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-06-22 15:02:40
|
Revision: 723 http://treebase.svn.sourceforge.net/treebase/?rev=723&view=rev Author: rvos Date: 2010-06-22 15:02:32 +0000 (Tue, 22 Jun 2010) Log Message: ----------- Apparently there are situations where the list with authors has null elements in it. This probably due to some inconsistency in the database, but it was causing null pointer exceptions in the code here. I've coded more defensively to take this possibility into account. Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java 2010-06-16 15:01:17 UTC (rev 722) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/Citation.java 2010-06-22 15:02:32 UTC (rev 723) @@ -482,13 +482,13 @@ if (size > 0) { for (int i = 0; i < size; i++) { - - authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); - - if (size > 1 && i == size - 2) { - authorsCitationStyle.append(", & "); - } else if (size > 1 && i < size - 2) { - authorsCitationStyle.append(", "); + if ( null != authors.get(i) ) { + authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); + if (size > 1 && i == size - 2) { + authorsCitationStyle.append(", & "); + } else if (size > 1 && i < size - 2) { + authorsCitationStyle.append(", "); + } } } @@ -510,12 +510,14 @@ int size = authors.size(); if (size > 0) { for ( int i = 0; i < size; i++ ) { - authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); - if ( size > 1 && i == size - 2 ) { - authorsCitationStyle.append(", & "); - } - else if (size > 1 && i < size - 2) { - authorsCitationStyle.append(", "); + if ( null != authors.get(i) ) { + authorsCitationStyle.append(authors.get(i).getFullNameCitationStyle()); + if ( size > 1 && i == size - 2 ) { + authorsCitationStyle.append(", & "); + } + else if (size > 1 && i < size - 2) { + authorsCitationStyle.append(", "); + } } } } @@ -696,8 +698,10 @@ annotations.add(new Annotation(Constants.DCURI,"dc:title",getTitle())); annotations.add(new Annotation(Constants.DCURI,"dc:creator",getAuthorsAsString())); for ( Person person : getAuthors() ) { - String personName = person.getFullNameCitationStyle(); - annotations.add(new Annotation(Constants.DCURI,"dc:contributor",personName)); + if ( null != person ) { + String personName = person.getFullNameCitationStyle(); + annotations.add(new Annotation(Constants.DCURI,"dc:contributor",personName)); + } } try { if ( null != getPublishYear() ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |