Project

General

Profile

Revision 93ad7e54

ID93ad7e545dc77e63b68e434c62c8560a68bb9dfb
Parent 8bbb7d89
Child b45755b5

Added by Andreas Müller almost 2 years ago

fix #8673 Add CdmLinkSource to OriginalSourceBase

View differences:

cdmlib-cache/src/main/resources/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml
77 77
      <mapping class="eu.etaxonomy.cdm.model.common.Annotation"/>
78 78
      <mapping class="eu.etaxonomy.cdm.model.common.AnnotationType"/>
79 79
      <mapping class="eu.etaxonomy.cdm.model.common.Credit"/>
80
      <mapping class="eu.etaxonomy.cdm.model.common.CdmLinkBase"/>
80 81
      <mapping class="eu.etaxonomy.cdm.model.common.Extension"/>
81 82
      <mapping class="eu.etaxonomy.cdm.model.common.ExtensionType"/>
82 83
      <mapping class="eu.etaxonomy.cdm.model.common.IdentifiableSource"/>
......
88 89
      <mapping class="eu.etaxonomy.cdm.model.common.LSIDAuthority"/>
89 90
      <mapping class="eu.etaxonomy.cdm.model.common.Marker"/>
90 91
      <mapping class="eu.etaxonomy.cdm.model.common.MarkerType"/>
91
      <mapping class="eu.etaxonomy.cdm.model.reference.OriginalSourceBase"/>
92 92
      <mapping class="eu.etaxonomy.cdm.model.common.RelationshipTermBase"/>
93 93
      
94 94
      <!-- Description Package -->
......
200 200
      
201 201
      <!-- Reference Package -->
202 202
      <mapping class="eu.etaxonomy.cdm.model.reference.Reference"/>
203

  
203
      <mapping class="eu.etaxonomy.cdm.model.reference.OriginalSourceBase"/>
204
      <mapping class="eu.etaxonomy.cdm.model.reference.CdmLinkSource"/>
205
      
204 206
      <!-- Taxon Package -->
205 207
      <mapping class="eu.etaxonomy.cdm.model.taxon.Synonym"/>
206 208
      <mapping class="eu.etaxonomy.cdm.model.taxon.SynonymType"/>
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/CdmBase.java
39 39
import javax.xml.bind.annotation.XmlType;
40 40
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
41 41

  
42
import org.apache.commons.lang3.StringUtils;
42 43
import org.apache.log4j.Logger;
43 44
import org.hibernate.annotations.NaturalId;
44 45
import org.hibernate.annotations.Type;
......
51 52
import org.hibernate.search.annotations.Store;
52 53
import org.joda.time.DateTime;
53 54

  
54
import eu.etaxonomy.cdm.common.CdmUtils;
55 55
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
56 56
import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
57 57
import eu.etaxonomy.cdm.hibernate.search.NotNullAwareIdBridge;
......
504 504

  
505 505

  
506 506
    /**
507
     * Returns true if the given String is blank.
507
     * Returns <code>true</code> if the given String is blank.
508 508
     * @param str the String to check
509
     * @see CdmUtils#isBlank(String)
510
     * @return true if str is blank
509
     * @see StringUtils#isBlank(String)
510
     * @return <code>true</code> if str is blank, <code>false</code> otherwise
511 511
     */
512 512
    protected boolean isBlank(String str) {
513
        return CdmUtils.isBlank(str);
513
        return StringUtils.isBlank(str);
514
    }
515

  
516
    /**
517
     * Returns <code>true</code> if the given String is not blank.
518
     * @param str the String to check
519
     * @see StringUtils#isNotBlank(String)
520
     * @return <code>true</code> if str is not blank, <code>false</code> otherwise
521
     */
522
    protected boolean isNotBlank(String str) {
523
        return StringUtils.isNotBlank(str);
514 524
    }
515 525

  
516 526

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/CdmLinkBase.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.model.common;
10

  
11
import javax.persistence.Entity;
12
import javax.persistence.Inheritance;
13
import javax.persistence.InheritanceType;
14
import javax.persistence.Table;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlType;
18

  
19
import org.hibernate.envers.Audited;
20

  
21
/**
22
 * Base class for subclasses linking to other CDM objects.
23
 *
24
 * @author a.mueller
25
 * @since 09.11.2019
26
 */
27
@XmlAccessorType(XmlAccessType.FIELD)
28
@XmlType(name = "CdmLink", propOrder = {
29
})
30
@Entity
31
@Audited
32
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
33
@Table(name="CdmLink")
34
public abstract class CdmLinkBase extends VersionableEntity {
35

  
36
    private static final long serialVersionUID = -1418100748281536524L;
37

  
38
// ************************* CLONE *******************/
39

  
40
    @Override
41
    public Object clone() throws CloneNotSupportedException {
42
        CdmLinkBase result = (CdmLinkBase)super.clone();
43

  
44
        return result;
45
  }
46

  
47
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableEntity.java
55 55
import eu.etaxonomy.cdm.jaxb.FormattedTextAdapter;
56 56
import eu.etaxonomy.cdm.jaxb.LSIDAdapter;
57 57
import eu.etaxonomy.cdm.model.media.Rights;
58
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
58 59
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
59 60
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
60 61
import eu.etaxonomy.cdm.model.reference.Reference;
......
578 579
        }
579 580
    }
580 581

  
581

  
582
    /**
583
     * {@inheritDoc}
584
     */
585 582
    @Override
586 583
    protected IdentifiableSource createNewSource(OriginalSourceType type, String idInSource, String idNamespace,
587
            Reference reference, String microReference, String originalInfo) {
588
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo);
584
            Reference reference, String microReference, String originalInfo, ICdmTarget target) {
585
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo, target);
589 586
    }
590 587

  
591 588
//******************************** TO STRING *****************************************************/
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableSource.java
15 15
import org.apache.log4j.Logger;
16 16
import org.hibernate.envers.Audited;
17 17

  
18
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
18 19
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
19 20
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
20 21
import eu.etaxonomy.cdm.model.reference.Reference;
......
80 81
        return result;
81 82
    }
82 83

  
84
   public static IdentifiableSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference
85
           reference, String microReference, String originalInfo, ICdmTarget target){
86
        IdentifiableSource result = NewInstance(type, id, idNamespace, reference,
87
                microReference, originalInfo);
88
       result.setCdmSource(target);
89
       return result;
90
   }
91

  
83 92
	public static IdentifiableSource NewPrimarySourceInstance(Reference citation, String microCitation){
84 93
		IdentifiableSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
85 94
		result.setCitation(citation);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IntextReference.java
23 23
import eu.etaxonomy.cdm.model.media.Media;
24 24
import eu.etaxonomy.cdm.model.name.TaxonName;
25 25
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
26
import eu.etaxonomy.cdm.model.reference.CdmLinkSource;
26 27
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
27 28
import eu.etaxonomy.cdm.model.reference.Reference;
28 29
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
......
39 40
 * @see #4706
40 41
 *
41 42
 * @author a.mueller
42
 *
43 43
 */
44 44
@XmlAccessorType(XmlAccessType.FIELD)
45 45
@XmlType(name = "IntextReference", propOrder = {
......
58 58
})
59 59
@Entity
60 60
@Audited
61
public class IntextReference extends VersionableEntity {
62
	private static final long serialVersionUID = -7002541566256975424L;
61
public class IntextReference extends CdmLinkBase {
62

  
63
    private static final long serialVersionUID = -7002541566256975424L;
63 64

  
64 65
    @XmlElement(name = "TaxonName")
65 66
    @XmlIDREF
......
230 231
    * Returns the target object. Throws an {@link IllegalStateException} if no target
231 232
    * is defined.
232 233
    *
233
    * @return
234
    * @see CdmLinkSource#getTarget()
234 235
    */
235 236
   public IIntextReferenceTarget getTarget() {
236 237
       if (agent != null){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/SourcedEntityBase.java
28 28
import org.hibernate.annotations.CascadeType;
29 29
import org.hibernate.envers.Audited;
30 30

  
31
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
31 32
import eu.etaxonomy.cdm.model.reference.ISourceable;
32 33
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
33 34
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
......
98 99
        if (id == null && idNamespace == null && citation == null && microCitation == null){
99 100
            return null;
100 101
        }
101
        SOURCE source = createNewSource(type, id, idNamespace, citation, microCitation, null);
102
        SOURCE source = createNewSource(type, id, idNamespace, citation, microCitation, null, null);
102 103
        addSource(source);
103 104
        return source;
104 105
    }
......
109 110
        if (reference == null && isBlank(microReference) && isBlank(originalInformation)){
110 111
            return null;
111 112
        }
112
        SOURCE source = createNewSource(type, null, null, reference, microReference, originalInformation);
113
        SOURCE source = createNewSource(type, null, null, reference, microReference, originalInformation, null);
114
        addSource(source);
115
        return source;
116
    }
117

  
118
    @Override
119
    public SOURCE addAggregationSource(ICdmTarget target) {
120
        SOURCE source = createNewSource(OriginalSourceType.Aggregation, null, null, null,
121
                null, null, target);
113 122
        addSource(source);
114 123
        return source;
115 124
    }
......
129 138
        if (id == null && idNamespace == null && citation == null && microCitation == null){
130 139
            return null;
131 140
        }
132
        SOURCE source = createNewSource(OriginalSourceType.Import, id, idNamespace, citation, microCitation, null);
141
        SOURCE source = createNewSource(OriginalSourceType.Import, id, idNamespace, citation, microCitation, null, null);
133 142
        addSource(source);
134 143
        return source;
135 144
    }
......
139 148
        if (citation == null && microCitation == null){
140 149
            return null;
141 150
        }
142
        SOURCE source = createNewSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, citation, microCitation, null);
151
        SOURCE source = createNewSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, citation, microCitation, null, null);
143 152
        addSource(source);
144 153
        return source;
145 154
    }
......
174 183
    }
175 184

  
176 185
    protected abstract SOURCE createNewSource(OriginalSourceType type, String idInSource, String idNamespace,
177
            Reference citation, String microReference, String originalInformation);
186
            Reference citation, String microReference, String originalInformation, ICdmTarget target);
178 187

  
179 188
//****************** CLONE ************************************************/
180 189

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/VersionableEntity.java
62 62
@XmlJavaTypeAdapter(value=DateTimeAdapter.class,type=DateTime.class)
63 63
@MappedSuperclass
64 64
@Audited
65
public abstract class VersionableEntity extends CdmBase implements IVersionableEntity{
66
	private static final long serialVersionUID = 1409299200302758513L;
65
public abstract class VersionableEntity
66
        extends CdmBase
67
        implements IVersionableEntity{
68

  
69
    private static final long serialVersionUID = 1409299200302758513L;
67 70
	@SuppressWarnings("unused")
68 71
	private static final Logger logger = Logger.getLogger(VersionableEntity.class);
69 72

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/CategoricalData.java
66 66
@Audited
67 67
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
68 68
public class CategoricalData extends DescriptionElementBase {
69

  
69 70
    private static final long serialVersionUID = -6298361966947668998L;
70 71
    private static final Logger logger = Logger.getLogger(CategoricalData.class);
71 72

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionBase.java
52 52
import eu.etaxonomy.cdm.model.name.TaxonName;
53 53
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
54 54
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
55
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
55 56
import eu.etaxonomy.cdm.model.reference.Reference;
56 57
import eu.etaxonomy.cdm.model.taxon.Taxon;
57 58
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
......
89 90
    @ClassBridge(impl=GroupByTaxonClassBridge.class)
90 91
})
91 92
public abstract class DescriptionBase<S extends IIdentifiableEntityCacheStrategy>
92
        extends IdentifiableEntity<S> {
93
        extends IdentifiableEntity<S>
94
        implements ICdmTarget{
93 95

  
94 96
    private static final long serialVersionUID = 5504218413819040193L;
95 97
    private static final Logger logger = Logger.getLogger(DescriptionBase.class);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementBase.java
55 55
import eu.etaxonomy.cdm.model.media.Media;
56 56
import eu.etaxonomy.cdm.model.name.TaxonName;
57 57
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
58
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
58 59
import eu.etaxonomy.cdm.model.reference.IOriginalSource;
59 60
import eu.etaxonomy.cdm.model.reference.ISourceable;
60 61
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
......
96 97
@Entity
97 98
@Audited
98 99
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
99
public abstract class DescriptionElementBase extends AnnotatableEntity
100
public abstract class DescriptionElementBase
101
        extends AnnotatableEntity
100 102
        implements ISourceable<DescriptionElementSource>, IModifiable, IMultiLanguageTextHolder{
101 103

  
102 104
    private static final long serialVersionUID = 5000910777835755905L;
......
480 482
    }
481 483

  
482 484
    @Override
485
    public DescriptionElementSource addAggregationSource(ICdmTarget target) {
486
        DescriptionElementSource source = DescriptionElementSource.NewInstance(
487
                OriginalSourceType.Aggregation, null, null, null, null,
488
                null, null, target);
489
        addSource(source);
490
        return source;
491
    }
492

  
493
    @Override
483 494
    public void removeSource(DescriptionElementSource source) {
484 495
        this.sources.remove(source);
485 496
    }
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementSource.java
24 24

  
25 25
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
26 26
import eu.etaxonomy.cdm.model.name.TaxonName;
27
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
27 28
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
28 29
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
29 30
import eu.etaxonomy.cdm.model.reference.Reference;
......
101 102
		return result;
102 103
	}
103 104

  
105
    public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace,
106
            Reference citation, String microReference, TaxonName nameUsedInSource, String originalNameString, ICdmTarget target){
107
        DescriptionElementSource result = NewInstance(type, id, idNamespace, citation, microReference, nameUsedInSource, originalNameString);
108
        result.setCdmSource(target);
109
        return result;
110
    }
111

  
104 112
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microCitation){
105 113
		DescriptionElementSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
106 114
		result.setCitation(citation);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/metadata/CdmMetaData.java
58 58
	 * be handled by SCHEMA_VALIDATION.UPDATE
59 59
	 * The last number represents the date of change.
60 60
	 */
61
	private static final String dbSchemaVersion = "5.11.1.0.20191108";
61
//	private static final String dbSchemaVersion = "5.11.1.0.20191108";
62 62
//  private static final String dbSchemaVersion = "5.11.0.0.20191104";
63
//    private static final String dbSchemaVersion = "5.8.2.0.20190815";
63
    private static final String dbSchemaVersion = "5.11.2.0.20191109";
64 64

  
65 65

  
66 66
	/* END OF CONFUSION */
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TypeDesignationBase.java
37 37
import eu.etaxonomy.cdm.model.common.CdmBase;
38 38
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
39 39
import eu.etaxonomy.cdm.model.common.SourcedEntityBase;
40
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
40 41
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
41 42
import eu.etaxonomy.cdm.model.reference.Reference;
42 43
import eu.etaxonomy.cdm.validation.Level2;
......
272 273
        }
273 274
    }
274 275

  
275

  
276
    /**
277
     * {@inheritDoc}
278
     */
279 276
    @Override
280 277
    protected IdentifiableSource createNewSource(OriginalSourceType type, String idInSource, String idNamespace,
281
            Reference reference, String microReference, String originalInfo) {
282
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo);
278
            Reference reference, String microReference, String originalInfo, ICdmTarget target) {
279
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo, target);
283 280
    }
284 281

  
285 282

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/CdmLinkSource.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.model.reference;
10

  
11
import javax.persistence.Entity;
12
import javax.persistence.FetchType;
13
import javax.persistence.ManyToOne;
14
import javax.xml.bind.annotation.XmlAccessType;
15
import javax.xml.bind.annotation.XmlAccessorType;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlIDREF;
18
import javax.xml.bind.annotation.XmlRootElement;
19
import javax.xml.bind.annotation.XmlSchemaType;
20
import javax.xml.bind.annotation.XmlType;
21

  
22
import org.hibernate.envers.Audited;
23

  
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.common.CdmLinkBase;
26
import eu.etaxonomy.cdm.model.common.IntextReference;
27
import eu.etaxonomy.cdm.model.description.DescriptionBase;
28

  
29
/**
30
 * Class to link to other CdmBase objects within the context of
31
 * {@link OriginalSourceBase information sources}.
32
 *
33
 * @author a.mueller
34
 * @since 09.11.2019
35
 */
36
@XmlAccessorType(XmlAccessType.FIELD)
37
@XmlType(name = "CdmLinkSource", propOrder = {
38
//    "source",
39
    "description"
40
})
41
@XmlRootElement(name = "CdmLinkSource")
42
@Entity
43
@Audited
44
public class CdmLinkSource extends CdmLinkBase {
45

  
46
    private static final long serialVersionUID = 6600576878001716986L;
47

  
48
// // ************* Source ***********************/
49
//
50
//    @XmlElement(name = "Source")
51
//    @XmlIDREF
52
//    @XmlSchemaType(name = "IDREF")
53
//    @OneToOne(fetch = FetchType.LAZY, mappedBy="cdmSource")
54
//    private OriginalSourceBase<?> source;
55

  
56
// **************** Targets ************************/
57

  
58
    @XmlElement(name = "Description")
59
    @XmlIDREF
60
    @XmlSchemaType(name = "IDREF")
61
    @ManyToOne(fetch = FetchType.LAZY)
62
    private DescriptionBase<?> description;
63

  
64
// ************************ FACTORY *********************/
65

  
66
    public static CdmLinkSource NewInstance(ICdmTarget target) {
67
        return new CdmLinkSource(target);
68
    }
69

  
70
//******************* CONSTRUCTOR *********************/
71

  
72
    @SuppressWarnings("unused")
73
    private CdmLinkSource(){}  //for JAXB
74

  
75
    public CdmLinkSource(ICdmTarget target) {
76
//        this.source = source;
77
        setTarget(target);
78
    }
79

  
80
//***************** GETTER / SETTER *****************/
81

  
82
    /**
83
     * Returns the target object. Throws an {@link IllegalStateException} if no target
84
     * is defined.
85
     *
86
     * @see IntextReference#getTarget()
87
     */
88
    public ICdmTarget getTarget() {
89
        if (description != null){
90
            return description;
91
        }else{
92
            throw new IllegalStateException("CdmSource has no target object defined");
93
        }
94
    }
95

  
96
    public void setTarget(ICdmTarget target) {
97
        target = CdmBase.deproxy(target);
98
        if (target instanceof DescriptionBase<?>){
99
            this.description = (DescriptionBase<?>)target;
100
        }else{
101
            throw new IllegalArgumentException("Target class not supported by CdmSource");
102
        }
103
    }
104

  
105
// ********************************* CLONE **********************************/
106

  
107
    @Override
108
    public Object clone() throws CloneNotSupportedException {
109
        CdmLinkSource result = (CdmLinkSource)super.clone();
110

  
111
        return result;
112
    }
113

  
114
//    public CdmLinkSource clone(OriginalSourceBase<?> source) {
115
//        CdmLinkSource result;
116
//        try {
117
//            result = (CdmLinkSource)super.clone();
118
////            result.source = source;
119
//            return result;
120
//        } catch (CloneNotSupportedException e) {
121
//            throw new RuntimeException(e);  //does not happen
122
//        }
123
//    }
124

  
125
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ICdmTarget.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.model.reference;
10

  
11
/**
12
 * @author a.mueller
13
 * @since 09.11.2019
14
 */
15
public interface ICdmTarget {
16

  
17
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/IOriginalSource.java
108 108
	 */
109 109
	public void setCitation(Reference citation);
110 110

  
111
	/**
112
	 * @return the link to another CDM object which is the source
113
	 */
114
	public CdmLinkSource getCdmSource();
115

  
116
    /**
117
     * @see #getCdmSource()
118
     */
119
    public void setCdmSource(CdmLinkSource cdmLinkSource);
120

  
121
    /**
122
     * Shortcut to add a {@link CdmLinkSource}
123
     * @see #setCdmSource()
124
     */
125
    public void setCdmSource(ICdmTarget cdmTarget);
111 126
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ISourceable.java
34 34

  
35 35
	/**
36 36
	 * Adds a source that is newly created by its components. If all components except for the
37
	 * type are <code>null</null>
38
	 * no source is added.
37
	 * type are <code>null</null> no source is added.
38
	 *
39 39
     * @param type the {@link OriginalSourceType type} of the source
40 40
     * @param idInSource the id used in the source
41 41
     * @param idNamespace the namespace for the id in the source
......
49 49
     * @param reference
50 50
     * @param microReference
51 51
     * @param originalInformation
52
     * @return
52
     * @return the added source
53 53
     */
54 54
	public T addSource(OriginalSourceType type, Reference reference, String microReference, String originalInformation);
55 55

  
56
	/**
57
	 * Adds a source which links to another CDM object as source.
58
	 * @param target the target CDM source
59
	 * @return the aggregation source
60
	 */
61
	public T addAggregationSource(ICdmTarget target);
56 62

  
57 63
	/**
58 64
	 * Removes a source from this object
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/OriginalSourceBase.java
19 19
import javax.persistence.Inheritance;
20 20
import javax.persistence.InheritanceType;
21 21
import javax.persistence.OneToMany;
22
import javax.persistence.OneToOne;
22 23
import javax.persistence.Table;
23 24
import javax.validation.constraints.NotNull;
24 25
import javax.xml.bind.annotation.XmlAccessType;
......
26 27
import javax.xml.bind.annotation.XmlAttribute;
27 28
import javax.xml.bind.annotation.XmlElement;
28 29
import javax.xml.bind.annotation.XmlElementWrapper;
30
import javax.xml.bind.annotation.XmlIDREF;
29 31
import javax.xml.bind.annotation.XmlRootElement;
32
import javax.xml.bind.annotation.XmlSchemaType;
30 33
import javax.xml.bind.annotation.XmlType;
31 34

  
32 35
import org.apache.commons.lang.StringUtils;
......
57 60
    "type",
58 61
	"idInSource",
59 62
    "idNamespace",
63
    "cdmSource",
60 64
    "links"
61 65
})
62 66
@XmlRootElement(name = "OriginalSource")
......
66 70
@Table(name="OriginalSourceBase")
67 71
public abstract class OriginalSourceBase<T extends ISourceable>
68 72
        extends ReferencedEntityBase
69
        implements IOriginalSource<T>, IIntextReferenceTarget,Cloneable {
73
        implements IOriginalSource<T>, IIntextReferenceTarget {
70 74

  
71 75
	private static final long serialVersionUID = -1972959999261181462L;
72 76
	@SuppressWarnings("unused")
......
93 97
	@XmlElement(name = "IdNamespace")
94 98
	private String idNamespace;
95 99

  
100
    @XmlElement(name = "CdmSource")
101
    @XmlIDREF
102
    @XmlSchemaType(name = "IDREF")
103
    @OneToOne(fetch = FetchType.LAZY)
104
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
105
    private CdmLinkSource cdmSource;
106

  
96 107
    @XmlElementWrapper(name = "Links", nillable = true)
97 108
    @XmlElement(name = "Link")
98 109
    @OneToMany(fetch=FetchType.LAZY, orphanRemoval=true)
......
151 162
		this.type = type;
152 163
	}
153 164

  
165
	@Override
166
    public CdmLinkSource getCdmSource() {
167
        return cdmSource;
168
    }
169
	@Override
170
    public void setCdmSource(CdmLinkSource cdmSource) {
171
        this.cdmSource = cdmSource;
172
    }
173
    @Override
174
    public void setCdmSource(ICdmTarget cdmTarget){
175
        if (cdmTarget != null){
176
            this.cdmSource = CdmLinkSource.NewInstance(cdmTarget);
177
        }else{
178
            this.cdmSource = null;
179
        }
180
    }
181

  
154 182
//********************** External Links **********************************************
155 183

  
184

  
156 185
    public Set<ExternalLink> getLinks(){
157 186
        return this.links;
158 187
    }
......
182 211
		    result.addLink((ExternalLink)link.clone());
183 212
		}
184 213

  
214
		if (this.cdmSource != null){
215
		    result.setCdmSource((CdmLinkSource)this.cdmSource.clone());
216
		}
217

  
185 218
		//no changes to: idInSource
186 219
		return result;
187 220
	}
......
190 223
//************************ toString ***************************************/
191 224
	@Override
192 225
	public String toString(){
193
		if (StringUtils.isNotBlank(idInSource) || StringUtils.isNotBlank(idNamespace) ){
226
		if (isNotBlank(idInSource) || isNotBlank(idNamespace) ){
194 227
			return "OriginalSource:" + CdmUtils.concat(":", idNamespace, idInSource);
195 228
		}else{
196 229
			return super.toString();
......
199 232

  
200 233
//*********************************** EQUALS *********************************************************/
201 234

  
202
	/**
203
     * {@inheritDoc}
204
     */
205 235
    @Override
206 236
    public boolean equalsByShallowCompare(ReferencedEntityBase other) {
207 237

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/data/FullCoverageDataGenerator.java
401 401
		taxonDescription.addGeoScope(Country.GERMANY());
402 402
		handleIdentifiableEntity(taxonDescription);
403 403

  
404
		taxon.addAggregationSource(taxonDescription);
405

  
404 406
		cdmBases.add(taxon);
405 407

  
406 408
		//DescriptionElmenetBase  + source
......
416 418
		source.addLink(link);
417 419
		handleAnnotatableEntity(source);
418 420

  
419
		taxonDescription.addDescriptionSource(ref);
421
		taxonDescription.addDescriptionSource(ref);  //as long as it still exists
420 422

  
421 423

  
422 424
		//Specimen description
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/CdmUpdater.java
17 17
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
18 18
import eu.etaxonomy.cdm.database.CdmDataSource;
19 19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.cdm.database.update.v58_511.SchemaUpdater_511_5111;
20
import eu.etaxonomy.cdm.database.update.v58_511.SchemaUpdater_5111_5112;
21 21
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
22 22

  
23 23
/**
......
72 72
     * Returns the current CDM updater
73 73
     */
74 74
    private ISchemaUpdater getCurrentSchemaUpdater() {
75
        return SchemaUpdater_511_5111.NewInstance();
75
        return SchemaUpdater_5111_5112.NewInstance();
76 76
    }
77 77

  
78 78
    /**
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v34_35/SchemaUpdater_341_35.java
63 63
		String referencedTables[];
64 64
		String columnTypes[];
65 65

  
66
		List<ISchemaUpdaterStep> stepList = new ArrayList<ISchemaUpdaterStep>();
66
		List<ISchemaUpdaterStep> stepList = new ArrayList<>();
67 67

  
68 68

  
69 69
		//IntextReference
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v58_511/SchemaUpdater_5111_5112.java
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

  
10
package eu.etaxonomy.cdm.database.update.v58_511;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.database.update.ColumnAdder;
18
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
19
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
20
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
21
import eu.etaxonomy.cdm.database.update.TableNameChanger;
22

  
23
/**
24
 * @author a.mueller
25
 * @date 01.11.2019
26
 */
27
public class SchemaUpdater_5111_5112 extends SchemaUpdaterBase {
28

  
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(SchemaUpdater_5111_5112.class);
31

  
32
	private static final String startSchemaVersion = "5.11.1.0.20191108";
33
	private static final String endSchemaVersion = "5.11.2.0.20191109";
34

  
35
// ********************** FACTORY METHOD *************************************
36

  
37
	public static SchemaUpdater_5111_5112 NewInstance() {
38
		return new SchemaUpdater_5111_5112();
39
	}
40

  
41
	protected SchemaUpdater_5111_5112() {
42
		super(startSchemaVersion, endSchemaVersion);
43
	}
44

  
45
	@Override
46
	protected List<ISchemaUpdaterStep> getUpdaterList() {
47

  
48
		String stepName;
49
		String tableName;
50
		String newColumnName;
51

  
52
		List<ISchemaUpdaterStep> stepList = new ArrayList<>();
53

  
54
        //##8673 add DTYPE to IntextReference
55
        stepName = "add DTYPE to IntextReference";
56
        tableName = "IntextReference";
57
        ColumnAdder.NewDTYPEInstance(stepList, stepName, tableName, "IntextReference", INCLUDE_AUDIT) ;
58

  
59
        //##8673 add description_id column to IntextReference
60
        stepName = "add description_id column to IntextReference";
61
        tableName = "IntextReference";
62
        newColumnName ="description_id";
63
        String referencedTable = "DescriptionBase";
64
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
65

  
66
        //##8673 rename table IntextReference to CdmLink
67
        stepName = "rename table IntextReference to CdmLink";
68
        String oldTableName = "IntextReference";
69
        String newTableName = "CdmLink";
70
        TableNameChanger.NewInstance(stepList, stepName, oldTableName, newTableName, INCLUDE_AUDIT);
71

  
72
        //##8673 add cdmSource_id to OriginalSourceBase
73
        stepName = "add cdmSource_id to OriginalSourceBase";
74
        tableName = "OriginalSourceBase";
75
        newColumnName ="cdmSource_id";
76
        referencedTable = "CdmLink";
77
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
78

  
79

  
80
        return stepList;
81
    }
82

  
83
    @Override
84
    public ISchemaUpdater getPreviousUpdater() {
85
        return SchemaUpdater_511_5111.NewInstance();
86
    }
87

  
88
    @Override
89
	public ISchemaUpdater getNextUpdater() {
90
		return null;
91
	}
92

  
93
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v58_511/SchemaUpdater_511_5111.java
61 61
    }
62 62

  
63 63
    @Override
64
    public ISchemaUpdater getPreviousUpdater() {
65
        return SchemaUpdater_582_511.NewInstance();
66
    }
67

  
68
    @Override
64 69
	public ISchemaUpdater getNextUpdater() {
65
		return null;
70
		return SchemaUpdater_5111_5112.NewInstance();
66 71
	}
67 72

  
68
	@Override
69
	public ISchemaUpdater getPreviousUpdater() {
70
		return SchemaUpdater_582_511.NewInstance();
71
	}
72 73
}
cdmlib-persistence/src/main/resources/eu/etaxonomy/cdm/hibernate.cfg.xml
66 66
      <mapping class="eu.etaxonomy.cdm.model.common.Annotation"/>
67 67
      <mapping class="eu.etaxonomy.cdm.model.common.AnnotationType"/>
68 68
      <mapping class="eu.etaxonomy.cdm.model.common.Credit"/>
69
      <mapping class="eu.etaxonomy.cdm.model.common.CdmLinkBase"/>
69 70
      <mapping class="eu.etaxonomy.cdm.model.common.Extension"/>
70 71
      <mapping class="eu.etaxonomy.cdm.model.common.ExtensionType"/>
71 72
      <mapping class="eu.etaxonomy.cdm.model.common.IdentifiableSource"/>
......
77 78
      <mapping class="eu.etaxonomy.cdm.model.common.LSIDAuthority"/>
78 79
      <mapping class="eu.etaxonomy.cdm.model.common.Marker"/>
79 80
      <mapping class="eu.etaxonomy.cdm.model.common.MarkerType"/>
80
      <mapping class="eu.etaxonomy.cdm.model.reference.OriginalSourceBase"/>
81 81
      <mapping class="eu.etaxonomy.cdm.model.common.RelationshipTermBase"/>
82 82
      
83 83
      <!-- Description Package -->
......
189 189
      
190 190
      <!-- Reference Package -->
191 191
      <mapping class="eu.etaxonomy.cdm.model.reference.Reference"/>
192

  
192
      <mapping class="eu.etaxonomy.cdm.model.reference.OriginalSourceBase"/>
193
      <mapping class="eu.etaxonomy.cdm.model.reference.CdmLinkSource"/>
194
      
193 195
      <!-- Taxon Package -->
194 196
      <mapping class="eu.etaxonomy.cdm.model.taxon.Synonym"/>
195 197
      <mapping class="eu.etaxonomy.cdm.model.taxon.SynonymType"/>
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestModelUpdate.java
46 46

  
47 47
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
48 48

  
49
		String database = (schema == DbSchemaValidation.VALIDATE  ? "cdm511" : "cdm52");
49
		String database = (schema == DbSchemaValidation.VALIDATE  ? "cdm58" : "cdm511");
50 50

  
51 51
		CdmDataSource dataSource = getDatasource(dbType, database);
52 52
 		try {
cdmlib-test/src/main/resources/dbscripts/001-cdm.h2.sql
2307 2307
    REVTYPE TINYINT
2308 2308
);
2309 2309
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.IDENTIFIER_MARKER_AUD;
2310
CREATE CACHED TABLE PUBLIC.INTEXTREFERENCE(
2310
CREATE CACHED TABLE PUBLIC.CDMLINK(
2311
    DTYPE VARCHAR(31) NOT NULL,
2311 2312
    ID INTEGER NOT NULL,
2312 2313
    UUID VARCHAR(36),
2313 2314
    CREATED TIMESTAMP,
......
2325 2326
	SOURCE_ID INT,
2326 2327
  	TAXON_ID INT,
2327 2328
  	TAXONNAME_ID INT,
2328
	KEY_ID INT
2329
	KEY_ID INT,
2330
	DESCRIPTION_ID INT
2329 2331
);
2330 2332
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.INTEXTREFERENCE;
2331
CREATE CACHED TABLE PUBLIC.INTEXTREFERENCE_AUD(
2333
CREATE CACHED TABLE PUBLIC.CDMLINK_AUD(
2334
    DTYPE VARCHAR(31) NOT NULL,
2332 2335
    ID INTEGER NOT NULL,
2333 2336
    REV INTEGER NOT NULL,
2334 2337
    REVTYPE TINYINT,
......
2348 2351
	SOURCE_ID INT,
2349 2352
  	TAXON_ID INT,
2350 2353
  	TAXONNAME_ID INT,
2351
	KEY_ID INT
2354
	KEY_ID INT,
2355
	DESCRIPTION_ID INT
2352 2356
);
2353 2357
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.INTEXTREFERENCE_AUD;
2354 2358
CREATE CACHED TABLE PUBLIC.INSTITUTIONALMEMBERSHIP(
......
3092 3096
    CREATEDBY_ID INTEGER,
3093 3097
    UPDATEDBY_ID INTEGER,
3094 3098
    CITATION_ID INTEGER,
3095
    NAMEUSEDINSOURCE_ID INTEGER
3099
    NAMEUSEDINSOURCE_ID INTEGER,
3100
	CDMSOURCE_ID INTEGER
3096 3101
);
3097 3102
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.ORIGINALSOURCEBASE;
3098 3103
CREATE CACHED TABLE PUBLIC.ORIGINALSOURCEBASE_AUD(
......
3111 3116
    CREATEDBY_ID INTEGER,
3112 3117
    UPDATEDBY_ID INTEGER,
3113 3118
    CITATION_ID INTEGER,
3114
    NAMEUSEDINSOURCE_ID INTEGER
3119
    NAMEUSEDINSOURCE_ID INTEGER,
3120
	CDMSOURCE_ID INTEGER
3115 3121
);
3116 3122
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.ORIGINALSOURCEBASE_AUD;
3117 3123
CREATE CACHED TABLE PUBLIC.ORIGINALSOURCEBASE_ANNOTATION(
cdmlib-test/src/main/resources/eu/etaxonomy/cdm/database/schema/dataset.dtd
2283 2283
    CREATEDBY_ID CDATA #IMPLIED
2284 2284
    UPDATEDBY_ID CDATA #IMPLIED
2285 2285
    CITATION_ID CDATA #IMPLIED
2286
    CDMSOURCE_ID CDATA #IMPLIED
2286 2287
>
2287 2288

  
2288 2289
<!ELEMENT ORIGINALSOURCEBASE_AUD EMPTY>
......
2300 2301
    CREATEDBY_ID CDATA #IMPLIED
2301 2302
    UPDATEDBY_ID CDATA #IMPLIED
2302 2303
    CITATION_ID CDATA #IMPLIED
2304
    CDMSOURCE_ID CDATA #IMPLIED
2303 2305
>
2304 2306

  
2305 2307
<!ELEMENT ORIGINALSOURCEBASE_ANNOTATION EMPTY>
cdmlib-test/src/test/resources/eu/etaxonomy/cdm/hibernate.cfg.xml
66 66
      <mapping class="eu.etaxonomy.cdm.model.common.Annotation"/>
67 67
      <mapping class="eu.etaxonomy.cdm.model.common.AnnotationType"/>
68 68
      <mapping class="eu.etaxonomy.cdm.model.common.Credit"/>
69
      <mapping class="eu.etaxonomy.cdm.model.common.CdmLinkBase"/>
69 70
      <mapping class="eu.etaxonomy.cdm.model.common.Extension"/>
70 71
      <mapping class="eu.etaxonomy.cdm.model.common.ExtensionType"/>
71 72
      <mapping class="eu.etaxonomy.cdm.model.common.IdentifiableSource"/>
......
77 78
      <mapping class="eu.etaxonomy.cdm.model.common.LSIDAuthority"/>
78 79
      <mapping class="eu.etaxonomy.cdm.model.common.Marker"/>
79 80
      <mapping class="eu.etaxonomy.cdm.model.common.MarkerType"/>
80
      <mapping class="eu.etaxonomy.cdm.model.reference.OriginalSourceBase"/>
81 81
      <mapping class="eu.etaxonomy.cdm.model.common.RelationshipTermBase"/>
82 82
      
83 83
      <!-- Description Package -->
......
189 189
      
190 190
      <!-- Reference Package -->
191 191
      <mapping class="eu.etaxonomy.cdm.model.reference.Reference"/>
192

  
192
      <mapping class="eu.etaxonomy.cdm.model.reference.OriginalSourceBase"/>
193
      <mapping class="eu.etaxonomy.cdm.model.reference.CdmLinkSource"/>
194
      
193 195
      <!-- Taxon Package -->
194 196
      <mapping class="eu.etaxonomy.cdm.model.taxon.Synonym"/>
195 197
      <mapping class="eu.etaxonomy.cdm.model.taxon.SynonymType"/>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)