Project

General

Profile

« Previous | Next » 

Revision d71868a2

Added by Andreas Müller about 3 years ago

ref #9327 add sec source to TaxonBase (with few open issues)

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonBase.java
12 12
import java.lang.reflect.Method;
13 13
import java.util.List;
14 14

  
15
import javax.persistence.Column;
16 15
import javax.persistence.Entity;
17 16
import javax.persistence.FetchType;
18 17
import javax.persistence.Index;
19 18
import javax.persistence.ManyToOne;
19
import javax.persistence.OneToOne;
20 20
import javax.persistence.Table;
21 21
import javax.persistence.Transient;
22 22
import javax.validation.constraints.NotNull;
......
51 51
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
52 52
import eu.etaxonomy.cdm.model.common.IPublishable;
53 53
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
54
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
54 55
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
55 56
import eu.etaxonomy.cdm.model.name.ITaxonNameBase;
56 57
import eu.etaxonomy.cdm.model.name.Rank;
57 58
import eu.etaxonomy.cdm.model.name.TaxonName;
59
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
58 60
import eu.etaxonomy.cdm.model.reference.Reference;
59 61
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
60 62
import eu.etaxonomy.cdm.strategy.cache.name.CacheUpdate;
......
62 64
import eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy;
63 65
import eu.etaxonomy.cdm.validation.Level2;
64 66
import eu.etaxonomy.cdm.validation.Level3;
65
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
66 67
import eu.etaxonomy.cdm.validation.annotation.TaxonNameCannotBeAcceptedAndSynonym;
67 68

  
68 69
/**
......
85 86
@XmlAccessorType(XmlAccessType.FIELD)
86 87
@XmlType(name = "TaxonBase", propOrder = {
87 88
    "name",
88
    "sec",
89
    "secSource",
89 90
    "doubtful",
90
    "secMicroReference",
91 91
    "appendedPhrase",
92 92
    "useNameCache",
93 93
    "publish"
......
144 144
    @NotNull(groups = Level2.class)
145 145
    private TaxonName name;
146 146

  
147
    // The concept reference
148
    @XmlElement(name = "Sec")
147
    //#9327
148
    @XmlElement(name = "SecSource")
149 149
    @XmlIDREF
150 150
    @XmlSchemaType(name = "IDREF")
151
    @ManyToOne(fetch = FetchType.LAZY)
152
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
153
    @NotNull(groups = Level2.class)
154
    @IndexedEmbedded
155
    private Reference sec;
156

  
157
    @XmlElement(name = "secMicroReference")
151
    @OneToOne(fetch = FetchType.LAZY, orphanRemoval=true, mappedBy="sourcedTaxon")
152
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE,CascadeType.DELETE})
158 153
    @CacheUpdate(noUpdate ="titleCache")
159
    @NullOrNotEmpty
160
    @Column(length=255)
161
    private String secMicroReference;
154
    @IndexedEmbedded
155
    private SecundumSource secSource;
162 156

  
163 157
    @XmlElement(name = "AppendedPhrase")
164 158
    private String appendedPhrase;
......
274 268
        this.publish = publish;
275 269
    }
276 270

  
277
    /**
278
     * Returns the {@link eu.etaxonomy.cdm.model.reference.Reference reference} of <i>this</i> (abstract) taxon.
279
     * This is the reference or the treatment using the {@link TaxonName taxon name}
280
     * in <i>this</i> (abstract) taxon.
281
     */
282
    public Reference getSec() {
283
        return sec;
271
  //*************** sec source *******************/
272

  
273
    public SecundumSource getSecSource(){
274
        return this.secSource;
275
    }
276

  
277
    protected DescriptionElementSource getSecSource(boolean createIfNotExist){
278
        if (this.secSource == null && createIfNotExist){
279
            setSecSource(SecundumSource.NewSecundumInstance(this));
280
        }
281
        return secSource;
284 282
    }
283

  
284
    public void setSecSource(SecundumSource secSource) throws IllegalArgumentException {
285
        //check state
286
        if (secSource != null && !OriginalSourceType.SecundumReference.equals(secSource.getType())
287
                ){
288
            throw new IllegalArgumentException("Secundum source must be of type " + OriginalSourceType.SecundumReference.getLabel());
289
        }
290
        this.secSource = secSource;
291
        if (secSource != null && secSource.getSourcedTaxon() != this){
292
            secSource.setSourcedTaxon(this);
293
        }
294
    }
295

  
296
    @Transient
297
    public Reference getSec(){
298
        return this.secSource == null? null:this.secSource.getCitation();
299
    }
300

  
301
    @Transient
302
    public void setSec(Reference secReference){
303
        if (secReference == null && this.getSecSource()==null){
304
            return;
305
        }else{
306
            getSecSource(true).setCitation(secReference);
307
        }
308
    }
309

  
285 310
    /**
286
     * @see  #getSec()
311
     * Returns the details string of the {@link #getSec() sec reference} assigned
312
     * to <i>this</i> taxon base. The details describe the exact localisation within
313
     * the publication used as sec reference. These are mostly
314
     * (implicitly) pages but can also be figures or tables or any other
315
     * element of a publication. A sec micro reference (details)
316
     * requires the existence of a sec reference.
287 317
     */
288
    public void setSec(Reference sec) {
289
        this.sec = sec;
318
    @Transient
319
    public String getSecMicroReference(){
320
        return this.secSource == null? null: this.secSource.getCitationMicroReference();
290 321
    }
291 322

  
292 323
    /**
293
     * @return the micro reference (detail) for the sec(undum)
294
     * reference
295
     * @see #getSec()
324
     * @see  #getSecMicroReference()
296 325
     */
297
    public String getSecMicroReference() {
298
        return secMicroReference;
326
    public void setSecMicroReference(String secMicroReference){
327
        secMicroReference = isBlank(secMicroReference)? null : secMicroReference;
328
        if (secMicroReference == null && this.getSecSource()==null){
329
            return;
330
        }else{
331
            this.getSecSource(true).setCitationMicroReference(secMicroReference);
332
        }
299 333
    }
300 334

  
301 335
    /**
302
     * @see #getSecMicroReference()
303
     * @see #getSec()
336
     * Checks if the source is completely empty and if empty removes it from the name.
304 337
     */
305
    public void setSecMicroReference(String secMicroReference) {
306
        this.secMicroReference = CdmUtils.Nb(secMicroReference);
338
    //TODO maybe this should be moved to a hibernate listener, but the listener solution may
339
    //work only for sec single sources as they are the only which are bidirectional
340
    protected void checkNullSource() {
341
        if (this.secSource != null && this.secSource.checkEmpty(true)){
342
            this.secSource = null;
343
        }
307 344
    }
308 345

  
309 346
// *********************************************

Also available in: Unified diff