Project

General

Profile

« Previous | Next » 

Revision 892efc69

Added by Andreas Kohlbecker almost 14 years ago

merging /branches/cdmlib/SPRINT-Chichorieae1/ to trunk

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ReferenceBase.java
60 60
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
61 61
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
62 62
import eu.etaxonomy.cdm.validation.Level2;
63
//import eu.etaxonomy.cdm.validation.annotation.InReference;
63 64
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
64 65

  
65 66
/**
......
102 103
    "school",
103 104
    "organization",
104 105
    "inReference"
106
//    ,"fullReference",
107
//    "abbreviatedReference"
105 108
})
106 109
@XmlRootElement(name = "ReferenceBase")
107 110
@Entity
......
109 112
@Audited
110 113
@javax.persistence.Table(name="Reference")
111 114
@Table(appliesTo="Reference", indexes = { @org.hibernate.annotations.Index(name = "ReferenceTitleCacheIndex", columnNames = { "titleCache" }) })
112

  
115
//@InReference(groups = Level2.class)
113 116
//public abstract class ReferenceBase<S extends IReferenceBaseCacheStrategy> extends IdentifiableMediaEntity<S> implements IParsable, IMergable, IMatchable, IArticle, IBook, IJournal, IBookSection,ICdDvd,IGeneric,IInProceedings, IProceedings, IPrintSeries, IReport, IThesis,IWebPage {
114
public class ReferenceBase<S extends IReferenceBaseCacheStrategy> extends IdentifiableMediaEntity<S> implements INomenclaturalReference, IArticle, IBook, IPatent, IDatabase, IJournal, IBookSection,ICdDvd,IGeneric,IInProceedings, IProceedings, IPrintSeries, IReport, IThesis,IWebPage, IPersonalCommunication, Cloneable {
117
public class ReferenceBase<S extends IReferenceBaseCacheStrategy> extends IdentifiableMediaEntity<S> implements INomenclaturalReference, IArticle, IBook, IPatent, IDatabase, IJournal, IBookSection,ICdDvd,IGeneric,IInProceedings, IProceedings, IPrintSeries, IReport, IThesis,IWebPage, IPersonalCommunication, IReferenceBase, Cloneable {
115 118
	private static final long serialVersionUID = -2034764545042691295L;
116 119
	private static final Logger logger = Logger.getLogger(ReferenceBase.class);
117 120
	
......
166 169
    @Field(index=Index.TOKENIZED)
167 170
    @NullOrNotEmpty
168 171
	@Length(max = 255)
169
	@Pattern(regexp = "ISBN\\x20(?=.{13}$)\\d{1,5}([- ])\\d{1,7}\\1\\d{1,6}\\1(\\d|X)$", groups = Level2.class, message = "{eu.etaxonomy.cdm.model.reference.ReferenceBase.isbn.message}") 
172
	@Pattern(regexp = "(?=.{13}$)\\d{1,5}([- ])\\d{1,7}\\1\\d{1,6}\\1(\\d|X)$", groups = Level2.class, message = "{eu.etaxonomy.cdm.model.reference.ReferenceBase.isbn.message}") 
170 173
	protected String isbn;
171 174
    
172 175
	@XmlElement(name = "ISSN")
173 176
	@Field(index=Index.TOKENIZED)
174 177
	@NullOrNotEmpty
175 178
	@Length(max = 255)
176
	@Pattern(regexp = "ISSN\\x20(?=.{9}$)\\d{4}([- ])\\d{4} (\\d|X)$", groups = Level2.class, message = "{eu.etaxonomy.cdm.model.reference.ReferenceBase.isbn.message}") 
179
	@Pattern(regexp = "(?=.{9}$)\\d{4}([- ])\\d{4} (\\d|X)$", groups = Level2.class, message = "{eu.etaxonomy.cdm.model.reference.ReferenceBase.issn.message}") 
177 180
	protected String issn;
178 181
	
179 182
    @XmlElement(name = "SeriesPart")
......
221 224
    @XmlIDREF
222 225
    @XmlSchemaType(name = "IDREF")
223 226
    @ManyToOne(fetch = FetchType.LAZY)
227

  
224 228
//    @IndexedEmbedded
225 229
    @Cascade(CascadeType.SAVE_UPDATE)
226
	protected ReferenceBase inReference;
230
    //@InReference(groups=Level2.class)
231
   	protected ReferenceBase inReference;
232
    
233
//    @XmlElement(name = "FullReference")
234
//    @XmlIDREF
235
//    @XmlSchemaType(name = "IDREF")
236
//    @ManyToOne(fetch = FetchType.LAZY)
237
////    @IndexedEmbedded
238
//    @Cascade(CascadeType.SAVE_UPDATE)
239
//    protected ReferenceBase fullReference;
240
//    
241
//    @XmlElement(name = "AbbreviatedReference")
242
//    @XmlIDREF
243
//    @XmlSchemaType(name = "IDREF")
244
//    @ManyToOne(fetch = FetchType.LAZY)
245
////    @IndexedEmbedded
246
//    @Cascade(CascadeType.SAVE_UPDATE)
247
//    protected ReferenceBase abbreviatedReference;
248
    
227 249
    
228 250
//********************************************************/    
229 251
    
......
283 305
    @XmlAttribute
284 306
    @Match(MatchMode.IGNORE)
285 307
    private int problemEnds = -1;
286
	
308
    
309
    @Transient
310
    @XmlAttribute
311
    @Match(MatchMode.IGNORE)
312
	private boolean cacheStrategyRectified = false; 
287 313
    
288 314
    protected ReferenceBase(){
289 315
		super();
......
517 543
	public void setReferenceAbstract(String referenceAbstract) {
518 544
		this.referenceAbstract = referenceAbstract;
519 545
	}
546
	
547
	
548
	
520 549

  
521 550
	/**
522 551
	 * Returns "true" if the isNomenclaturallyRelevant flag is set. This 
......
524 553
	 * published in <i>this</i> reference following the rules of a
525 554
	 * {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode nomenclature code} and is therefore used for
526 555
	 * nomenclatural citations. This flag will be set as soon as <i>this</i>
527
	 * reference is used as a nomenclatural reference for any taxon name.
556
	 * reference is used as a nomenclatural reference for any taxon name.<BR>
557
	 * FIXME what happens if the only taxon name referencing this reference is not 
558
	 * any longer using this reference as a nomenclatural reference. How does the 
559
	 * reference get informed about the fact that it is not nomenclaturally relevant 
560
	 * anymore? 
528 561
	 */
529 562
	public boolean isNomenclaturallyRelevant(){
530 563
		return this.nomenclaturallyRelevant;
......
537 570
		this.nomenclaturallyRelevant = nomenclaturallyRelevant;
538 571
	}
539 572
	
573

  
574
//	/**
575
//	 * Returns the full reference that belongs to this abbreviated reference. If this 
576
//	 * reference is not abbreviated the full reference should be <code>null</code>.<BR>
577
//	 * A full reference should be added to a reference
578
//	 * which represents the abbreviated form of a reference. The full reference can be used
579
//	 * by publication tools to link to the unabbreviated and therefore more complete version
580
//	 * of the reference.
581
//	 * 
582
//	 * @see #getAbbreviatedReference()
583
//	 * @return the full reference
584
//	 */
585
//	public ReferenceBase getFullReference() {
586
//		return fullReference;
587
//	}
588
//
589
//	/**
590
//	 * @see #getFullReference()
591
//	 * @param fullReference
592
//	 */
593
//	public void setFullReference(ReferenceBase fullReference) {
594
//		this.fullReference = fullReference;
595
//	}
596
//
597
//	/**
598
//	 * Returns the abbreviated reference that belongs to this full reference. If this 
599
//	 * reference is not a full reference the abbeviated referece must be <code>null</code>.<BR>
600
//	 * An abbreviated reference should be added to a reference which represents the long (full)
601
//	 * form of a reference.
602
//	 * In future this may become a set or handled differently as there are multiple 
603
//	 * 
604
//	 * @see #getFullReference()
605
//	 * @return the full reference
606
//	 */
607
//	public ReferenceBase getAbbreviatedReference() {
608
//		return abbreviatedReference;
609
//	}
610
//
611
//	/**
612
//	 * @see #getAbbreviatedReference()
613
//	 * @param abbreviatedReference
614
//	 * 
615
//	 */
616
//	public void setAbbreviatedReference(ReferenceBase abbreviatedReference) {
617
//		this.abbreviatedReference = abbreviatedReference;
618
//	}
619
	
540 620
//****************************************************  /	
541 621
	
542 622
//	/**
......
623 703
//		this.pages = pages;
624 704
//	}
625 705

  
706

  
626 707
	/**
627 708
	 * Returns a formatted string containing the entire reference citation,
628 709
	 * including authors, corresponding to <i>this</i> reference.
......
632 713
	// TODO implement
633 714
	@Transient
634 715
	public String getCitation(){
716
		rectifyCacheStrategy();
635 717
		if (cacheStrategy == null){
636 718
			logger.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
637 719
			return null;
......
640 722
		}
641 723
	}
642 724
	
725
	/* (non-Javadoc)
726
	 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
727
	 */
728
	public String generateTitle() {
729
		rectifyCacheStrategy();
730
		return super.generateTitle();
731
	}
732
	
643 733
	/**
644 734
	 * Returns a string representation for the year of publication / creation
645 735
	 * of <i>this</i> reference. The string is obtained by transformation of
......
814 904
	
815 905
	/* Casting methods */
816 906
	
817
	public IArticle castReferenceToArticle(ReferenceBase ref){
907
	public IArticle castReferenceToArticle(){
818 908
		((IArticle) this).setCacheStrategy(ArticleDefaultCacheStrategy.NewInstance());
819 909
		this.type = ReferenceType.Article;
820 910
		
821
		return (IArticle) ref;
911
		return (IArticle) this;
822 912
	}
823 913
	
824
	public IBook castReferenceToBook(ReferenceBase ref){
914
	public IBook castReferenceToBook(){
825 915
		((IBook) this).setCacheStrategy(BookDefaultCacheStrategy.NewInstance());
826 916
		this.type = ReferenceType.Book;
827
		return (IBook) ref;
917
		return (IBook) this;
828 918
	}
829 919
	
830
	public IBookSection castReferenceToBookSection(ReferenceBase ref){
920
	public IBookSection castReferenceToBookSection(){
831 921
		((IBookSection) this).setCacheStrategy(BookSectionDefaultCacheStrategy.NewInstance());
832 922
		this.type = ReferenceType.BookSection;
833 923
		
834
		return (IBookSection) ref;
924
		return (IBookSection) this;
835 925
	}
836 926
	
837
	public ICdDvd castReferenceToCdDvd(ReferenceBase ref){
927
	public ICdDvd castReferenceToCdDvd(){
838 928
		((ICdDvd) this).setCacheStrategy(ReferenceBaseDefaultCacheStrategy.NewInstance());
839 929
		this.type = ReferenceType.CdDvd;
840
		return (ICdDvd) ref;
930
		return (ICdDvd) this;
841 931
	}
842 932
	
843 933
	public IDatabase castReferenceToDatabase(){
......
861 951
	public IJournal castReferenceToJournal(){
862 952
		((IJournal) this).setCacheStrategy(JournalDefaultCacheStrategy.NewInstance());
863 953
		this.type = ReferenceType.Journal;
864
		return (IJournal) this;
954
		IJournal test = this;
955
		return (IJournal) test;
865 956
	}
866 957
	
867 958
	public IMap castReferenceToMap(ReferenceBase ref){
......
915 1006

  
916 1007
	
917 1008
	public String getNomenclaturalCitation(String microReference) {
1009
		rectifyCacheStrategy();
1010
		String typeName = this.getType()== null ? "(no type defined)" : this.getType().getMessage();
918 1011
		if (cacheStrategy == null){
919
			logger.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
1012
			logger.warn("No CacheStrategy defined for "+ typeName + ": " + this.getUuid());
920 1013
			return null;
921 1014
		}else{
922 1015
			if (cacheStrategy instanceof INomenclaturalReferenceCacheStrategy){
923 1016
				return ((INomenclaturalReferenceCacheStrategy)cacheStrategy).getNomenclaturalCitation(this,microReference);
924 1017
			}else {
925
				logger.warn("No INomenclaturalReferenceCacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
1018
				logger.warn("No INomenclaturalReferenceCacheStrategy defined for "+ typeName + ": " + this.getUuid());
926 1019
				return null;
927 1020
			}
928 1021
		}
929 1022
	}
930 1023

  
1024
	/**
1025
	 * The type property of this class is mapped on the field level to the data base column, so
1026
	 * Hibernate will consequently use the {@link org.hibernate.property.DirectPropertyAccessor} 
1027
	 * to set the property. This PropertyAccessor directly sets the field instead of using the according setter so 
1028
	 * the CacheStrategy is not correctly set after the initialization of the bean. Thus we need to 
1029
	 * validate the CacheStrategy before it is to be used.
1030
	 */
1031
	private void rectifyCacheStrategy() {
1032
		if(!cacheStrategyRectified ){
1033
			setType(getType());
1034
			cacheStrategyRectified = true;
1035
		}
1036
	}
1037

  
931 1038
	public IJournal getInJournal() {
932 1039
		IJournal journal = this.inReference;
933 1040
		return journal;

Also available in: Unified diff