Project

General

Profile

Revision 3c6ba3cd

ID3c6ba3cd2ac13cda7295367970a478290bbf52bf
Parent 3c6c0d2c
Child c524a825

Added by Andreas Müller over 3 years ago

fix #6459 Implement deduplication for IntextReferences

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/MarkupImportBase.java
1883 1883
	private String handleInLineReference(MarkupImportState state,XMLEventReader reader, XMLEvent parentEvent, MarkupNomenclatureImport nomenclatureImport)throws XMLStreamException {
1884 1884
		Reference reference = nomenclatureImport.handleReference(state, reader, parentEvent);
1885 1885
		fireWarningEvent("Check correct usage of inline reference", parentEvent, 3);
1886
		IntextReference intext = IntextReference.NewReferenceInstance(reference, null, 0, 0);
1886
		IntextReference intext = IntextReference.NewInstance(reference, null, 0, 0);
1887 1887
		save(reference, state);
1888 1888
		return intext.toInlineString(reference.getTitleCache());
1889 1889
	}
......
1932 1932
			        && !isStartingElement(next, SUB_HEADING)){
1933 1933
			    for (LabeledReference labeledRef : currentReferences.content){
1934 1934
			        if (labeledRef.ref != null){
1935
			            IntextReference intext = IntextReference.NewReferenceInstance(labeledRef.ref, null, 0, 0);
1935
			            IntextReference intext = IntextReference.NewInstance(labeledRef.ref, null, 0, 0);
1936 1936
			            inlineReferences.add(intext);
1937 1937
			            text += intext.toInlineString(labeledRef.label);
1938 1938
			        }else{
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/AgentBase.java
28 28
import org.hibernate.annotations.Table;
29 29
import org.hibernate.envers.Audited;
30 30

  
31
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
31 32
import eu.etaxonomy.cdm.model.location.Country;
32 33
import eu.etaxonomy.cdm.model.location.Point;
33 34
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
......
56 57
@Entity
57 58
@Audited
58 59
@Table(appliesTo="AgentBase", indexes = { @Index(name = "agentTitleCacheIndex", columnNames = { "titleCache" }) })
59
public abstract class AgentBase<S extends IIdentifiableEntityCacheStrategy<? extends AgentBase<S>>> extends IdentifiableMediaEntity<S> implements IMergable, IMatchable, Cloneable{
60
public abstract class AgentBase<S extends IIdentifiableEntityCacheStrategy<? extends AgentBase<S>>>
61
        extends IdentifiableMediaEntity<S>
62
        implements IMergable, IMatchable, IIntextReferenceTarget, Cloneable{
60 63
	private static final long serialVersionUID = 7732768617469448829L;
61 64
	@SuppressWarnings("unused")
62 65
	private static final Logger logger = Logger.getLogger(AgentBase.class);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Annotation.java
157 157
    public Set<IntextReference> getIntextReferences(){
158 158
		return this.intextReferences;
159 159
	}
160

  
160 161
	@Override
161 162
    public void addIntextReference(IntextReference intextReference){
162 163
		if (intextReference != null){
163
			intextReference.setAnnotation(this);
164
			intextReference.setReferencedEntity(this);
164 165
			getIntextReferences().add(intextReference);
165 166
		}
166 167
	}
......
169 170
    public void removeIntextReference(IntextReference intextReference){
170 171
		if(getIntextReferences().contains(intextReference)) {
171 172
			getIntextReferences().remove(intextReference);
172
			intextReference.setAnnotation((Annotation)null);
173
			intextReference.setReferencedEntity((Annotation)null);
173 174
		}
174 175
	}
175 176

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IIntextReferencable.java
4 4

  
5 5
public interface IIntextReferencable {
6 6

  
7
	
7

  
8 8
	//*************** INTEXT REFERENCE **********************************************
9
	
9

  
10 10
	public Set<IntextReference> getIntextReferences();
11

  
11 12
	public void addIntextReference(IntextReference intextReference);
12
	
13

  
13 14
	public void removeIntextReference(IntextReference intextReference);
15

  
16
	/**
17
	 * Returns the referenced text
18
     * @return the referenced text
19
     */
20
    public String getText();
21

  
22
    /**
23
     * Sets the referenced text.
24
     * @param text the new referenced text
25
     */
26
    public void setText(String text);
14 27
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IIntextReferenceTarget.java
1
/**
2
* Copyright (C) 2017 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
/**
12
 * Interface to flag those classes available as targets of
13
 * an {@link IntextReference}.
14
 *
15
 * @author a.mueller
16
 * @date 08.03.2017
17
 *
18
 */
19
public interface IIntextReferenceTarget extends ICdmBase{
20

  
21
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IntextReference.java
136 136

  
137 137
// ***************** FACTORY METHOD ***********************************
138 138

  
139
	public static IntextReference NewTaxonNameInstance(TaxonNameBase<?,?> taxonName, LanguageStringBase languageString, int start, int end){
140
		return new IntextReference(taxonName, null, null, null, null, null, languageString, start, end);
141
	}
142

  
143
	public static IntextReference NewTaxonInstance(TaxonBase<?> taxon, LanguageStringBase languageString, int start, int end){
144
		return new IntextReference(null, taxon, null, null, null, null, languageString, start, end);
145
	}
146

  
147
	public static IntextReference NewOccurrenceInstance(SpecimenOrObservationBase<?> occurrence, LanguageStringBase languageString, int start, int end){
148
		return new IntextReference(null, null, occurrence, null, null, null, languageString, start, end);
149
	}
150

  
151
	public static IntextReference NewAgentInstance(AgentBase<?> agent, LanguageStringBase languageString, int start, int end){
152
		return new IntextReference(null, null, null, agent, null, null, languageString, start, end);
153
	}
139
    public static IntextReference NewInstance(IIntextReferenceTarget target,
140
            IIntextReferencable referencedEntity, int start, int end){
141
        IntextReference result = new IntextReference(target, referencedEntity, start, end);
142
        return result;
143
    }
154 144

  
155
	public static IntextReference NewReferenceInstance(Reference reference, LanguageStringBase languageString, int start, int end){
156
		return new IntextReference(null, null, null, null, reference, null, languageString, start, end);
157
	}
145
//	public static IntextReference NewTaxonNameInstance(TaxonNameBase<?,?> taxonName, LanguageStringBase languageString, int start, int end){
146
//		return new IntextReference(taxonName, null, null, null, null, null, languageString, start, end);
147
//	}
148
//
149
//	public static IntextReference NewTaxonInstance(TaxonBase<?> taxon, LanguageStringBase languageString, int start, int end){
150
//		return new IntextReference(null, taxon, null, null, null, null, languageString, start, end);
151
//	}
152
//
153
//	public static IntextReference NewOccurrenceInstance(SpecimenOrObservationBase<?> occurrence, LanguageStringBase languageString, int start, int end){
154
//		return new IntextReference(null, null, occurrence, null, null, null, languageString, start, end);
155
//	}
156
//
157
//	public static IntextReference NewAgentInstance(AgentBase<?> agent, LanguageStringBase languageString, int start, int end){
158
//		return new IntextReference(null, null, null, agent, null, null, languageString, start, end);
159
//	}
160
//
161
//	public static IntextReference NewReferenceInstance(Reference reference, LanguageStringBase languageString, int start, int end){
162
//		return new IntextReference(null, null, null, null, reference, null, languageString, start, end);
163
//	}
164
//
165
//	public static IntextReference NewMediaInstance(Media media, LanguageStringBase languageString, int start, int end){
166
//		return new IntextReference(null, null, null, null, null, media, languageString, start, end);
167
//	}
168

  
169
	public static LanguageString NewReferencedLanguageString(IIntextReferenceTarget target, String pre, String middle, String post, Language language){
170
        LanguageString result = LanguageString.NewInstance(null, language);
171
        IntextReference intextReference = IntextReference.NewInstance(target, result, 0, 0);
172
	    result.addIntextReference(intextReference);
173
	    result.setText(pre + intextReference.toInlineString(middle) + post);
174
        return result;
175
    }
158 176

  
159
	public static IntextReference NewMediaInstance(Media media, LanguageStringBase languageString, int start, int end){
160
		return new IntextReference(null, null, null, null, null, media, languageString, start, end);
161
	}
177
    public static LanguageString NewReferencedLanguageString(IIntextReferenceTarget target, String text, int start, int end, Language language){
178
        if (start < 0 || end < 0 || start > end || end > text.length()){
179
            throw new IndexOutOfBoundsException("Start and end must be within bounds");
180
        }
181
        LanguageString result = LanguageString.NewInstance(text, language);
182
        IntextReference intextReference = IntextReference.NewInstance(target, result, start, end);
183
        result.addIntextReference(intextReference);
184
        String intext = text.substring(0, start) +
185
                intextReference.toInlineString(text.substring(start, end)) + text.substring(end);
186
        result.setText(intext);
187
        return result;
188
    }
162 189

  
163 190
//********************** CONSTRUCTOR ********************************************/
164 191

  
......
168 195
	@Deprecated //for hibernate use only
169 196
	private IntextReference(){}
170 197

  
171
	private IntextReference(TaxonNameBase<?, ?> taxonName, TaxonBase<?> taxon,
172
				SpecimenOrObservationBase<?> occurrence, AgentBase<?> agent,
173
				Reference reference, Media media, LanguageStringBase languageString, int start, int end) {
174
			super();
175
			this.taxonName = taxonName;
176
			this.taxon = taxon;
177
			this.occurrence = occurrence;
178
			this.agent = agent;
179
			this.reference = reference;
180
			this.media = media;
181
			if (languageString != null && languageString.isInstanceOf(LanguageString.class)){
182
				this.languageString = CdmBase.deproxy(languageString, LanguageString.class);
183
				this.languageString.addIntextReference(this);
184
			}else if (languageString != null && languageString.isInstanceOf(Annotation.class)){
185
				this.annotation = CdmBase.deproxy(languageString, Annotation.class);
186
				this.annotation.addIntextReference(this);
187
			}
188
			this.startPos = start;
189
			this.endPos = end;
190
	}
198
//	private IntextReference(TaxonNameBase<?, ?> taxonName, TaxonBase<?> taxon,
199
//				SpecimenOrObservationBase<?> occurrence, AgentBase<?> agent,
200
//				Reference reference, Media media, LanguageStringBase languageString, int start, int end) {
201
//			super();
202
//			this.taxonName = taxonName;
203
//			this.taxon = taxon;
204
//			this.occurrence = occurrence;
205
//			this.agent = agent;
206
//			this.reference = reference;
207
//			this.media = media;
208
//			if (languageString != null && languageString.isInstanceOf(LanguageString.class)){
209
//				this.languageString = CdmBase.deproxy(languageString, LanguageString.class);
210
//				this.languageString.addIntextReference(this);
211
//			}else if (languageString != null && languageString.isInstanceOf(Annotation.class)){
212
//				this.annotation = CdmBase.deproxy(languageString, Annotation.class);
213
//				this.annotation.addIntextReference(this);
214
//			}
215
//			this.startPos = start;
216
//			this.endPos = end;
217
//	}
218

  
219
	   private IntextReference(IIntextReferenceTarget target, IIntextReferencable referencedEntity, int start, int end) {
220
           super();
221
           setTarget(target);
222
           setReferencedEntity(referencedEntity);
223

  
224
           this.startPos = start;
225
           this.endPos = end;
226
   }
191 227

  
192 228

  
193
   private CDM_INTEXT_CLASS myClass(){
229
    private CDM_INTEXT_CLASS myClass(){
194 230
        if (agent != null){
195 231
            return CDM_INTEXT_CLASS.AGENT;
196 232
        }else if (media != null){
......
208 244
        }
209 245
    }
210 246

  
211
   private IdentifiableEntity<?> myEntity(){
247
// ****************    GETTER / SETTER ******************************************/
248

  
249
   /**
250
    * Returns the target object. Throws an {@link IllegalStateException} if no target
251
    * is defined.
252
    *
253
    * @return
254
    */
255
   public IIntextReferenceTarget getTarget() {
212 256
       if (agent != null){
213 257
           return agent;
214 258
       }else if (media != null){
......
226 270
       }
227 271
   }
228 272

  
229
// ****************    GETTER / SETTER ******************************************/
230

  
231
	public TaxonNameBase<?, ?> getTaxonName() {
232
		return taxonName;
233
	}
234
	public void setTaxonName(TaxonNameBase<?, ?> taxonName) {
235
		this.taxonName = taxonName;
236
	}
237

  
238

  
239
	public TaxonBase<?> getTaxon() {
240
		return taxon;
241
	}
242
	public void setTaxon(TaxonBase<?> taxon) {
243
		this.taxon = taxon;
244
	}
245

  
246
	public SpecimenOrObservationBase<?> getOccurrence() {
247
		return occurrence;
248
	}
249
	public void setOccurrence(SpecimenOrObservationBase<?> occurrence) {
250
		this.occurrence = occurrence;
251
	}
252

  
253
	public AgentBase<?> getAgent() {
254
		return agent;
255
	}
256
	public void setAgent(AgentBase<?> agent) {
257
		this.agent = agent;
258
	}
259

  
260
	public Reference getReference() {
261
		return reference;
262
	}
263
	public void setReference(Reference reference) {
264
		this.reference = reference;
265
	}
266

  
267

  
268

  
269
	public Media getMedia() {
270
		return media;
271
	}
272
	public void setMedia(Media media) {
273
		this.media = media;
274
	}
273
   /**
274
     * @param target
275
     */
276
    private void setTarget(IIntextReferenceTarget target) {
277
        target = CdmBase.deproxy(target);
278
        if (target instanceof TaxonNameBase){
279
            this.taxonName = (TaxonNameBase<?,?>)target;
280
        }else if (target instanceof TaxonBase){
281
            this.taxon = (TaxonBase<?>)target;
282
        }else if (target instanceof SpecimenOrObservationBase){
283
            this.occurrence = (SpecimenOrObservationBase<?>)target;
284
        }else if (target instanceof AgentBase){
285
            this.agent = (AgentBase<?>)target;
286
        }else if (target instanceof Reference){
287
            this.reference = (Reference)target;
288
        }else if (target instanceof Media){
289
            this.media = (Media)target;
290
        }else{
291
            throw new IllegalArgumentException("Target entity not yet handled: " + target.getClass().getName());
292
        }
293
    }
275 294

  
276
	public LanguageString getLanguageString() {
277
		return languageString;
278
	}
279
	public void setLanguageString(LanguageString languageString) {
280
		this.languageString = languageString;
281
	}
295
   public IIntextReferencable getReferencedEntity() {
296
       if (languageString != null){
297
           return languageString;
298
       }else if (annotation != null){
299
           return annotation;
300
       }else{
301
           return null;
302
       }
303
   }
282 304

  
283
	public Annotation getAnnotation() {
284
		return annotation;
285
	}
305
   /**
306
    * @param referencedEntity
307
    */
308
   public void setReferencedEntity(IIntextReferencable referencedEntity) {
309
       if (referencedEntity == null){
310
           this.annotation = null;
311
           this.languageString = null;
312
       }else if (this.getReferencedEntity() == referencedEntity){
313
           //do nothing
314
       }else{
315
           referencedEntity = CdmBase.deproxy(referencedEntity);
316
           if (referencedEntity instanceof LanguageString){
317
               this.languageString = (LanguageString)referencedEntity;
318
               this.annotation = null;
319
           }else if (referencedEntity instanceof Annotation){
320
               this.annotation = (Annotation)referencedEntity;
321
               this.languageString = null;
322
           }else{
323
               throw new IllegalArgumentException("Referenced entity type not yet supported: " + referencedEntity.getClass().getName());
324
           }
325
           if (!referencedEntity.getIntextReferences().contains(this)){
326
               referencedEntity.addIntextReference(this);
327
           }
328
       }
329
   }
286 330

  
287
	public void setAnnotation(Annotation annotation) {
288
		this.annotation = annotation;
289
	}
331
//	public TaxonNameBase<?, ?> getTaxonName() {
332
//		return taxonName;
333
//	}
334
//	public void setTaxonName(TaxonNameBase<?, ?> taxonName) {
335
//		this.taxonName = taxonName;
336
//	}
337
//
338
//
339
//	public TaxonBase<?> getTaxon() {
340
//		return taxon;
341
//	}
342
//	public void setTaxon(TaxonBase<?> taxon) {
343
//		this.taxon = taxon;
344
//	}
345
//
346
//	public SpecimenOrObservationBase<?> getOccurrence() {
347
//		return occurrence;
348
//	}
349
//	public void setOccurrence(SpecimenOrObservationBase<?> occurrence) {
350
//		this.occurrence = occurrence;
351
//	}
352
//
353
//	public AgentBase<?> getAgent() {
354
//		return agent;
355
//	}
356
//	public void setAgent(AgentBase<?> agent) {
357
//		this.agent = agent;
358
//	}
359
//
360
//	public Reference getReference() {
361
//		return reference;
362
//	}
363
//	public void setReference(Reference reference) {
364
//		this.reference = reference;
365
//	}
366
//
367
//	public Media getMedia() {
368
//		return media;
369
//	}
370
//	public void setMedia(Media media) {
371
//		this.media = media;
372
//	}
373

  
374
//	public LanguageString getLanguageString() {
375
//		return languageString;
376
//	}
377
//	protected void setLanguageString(LanguageString languageString) {
378
//		this.languageString = languageString;
379
//	}
380
//
381
//	public Annotation getAnnotation() {
382
//		return annotation;
383
//	}
384
//
385
//	public void setAnnotation(Annotation annotation) {
386
//		this.annotation = annotation;
387
//	}
290 388

  
291 389
	public int getStartPos() {
292 390
		return startPos;
......
305 403
	private static final String CDM_PREFIX = "cdm:";
306 404
	public String toInlineString(String innerText){
307 405
	    String tag = CDM_PREFIX + myClass().tag();
308
	    IdentifiableEntity<?> entity = myEntity();
406
	    IIntextReferenceTarget entity = getTarget();
309 407
	    String attributes = " cdmId='" + entity.getUuid() + "' intextId='" + this.getUuid() + "'" + otherAttributes(entity);
310 408
	    String result;
311 409
	    if (StringUtils.isNotEmpty(innerText)){
......
321 419
     * @param entity
322 420
     * @return
323 421
     */
324
    private String otherAttributes(IdentifiableEntity<?> entity) {
422
    private String otherAttributes(IIntextReferenceTarget entity) {
325 423
        return "";
326 424
    }
327 425

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/LanguageString.java
63 63
    private void setIntextReferences(Set<IntextReference> intextReferences){
64 64
        this.intextReferences = intextReferences;
65 65
    }
66

  
67

  
68
    public IntextReference addIntextReference(IIntextReferenceTarget target, String start, String inner, String end){
69
        IntextReference intextReference = IntextReference.NewInstance(target, this, 0, 0);
70
        setText(start + intextReference.toInlineString(inner) + end);
71
        getIntextReferences().add(intextReference);
72
        return intextReference;
73
    }
74
    public IntextReference addIntextReference(IIntextReferenceTarget target, int start, int end){
75
        if (start < 0 || end < 0 || start > end || end > text.length()){
76
            throw new IndexOutOfBoundsException("Start and end must be within bounds");
77
        }
78
        IntextReference intextReference = IntextReference.NewInstance(target, this, 0, 0);
79
        String text = this.getText();
80
        setText(text.substring(0, start) + intextReference.toInlineString(text.substring(start,end))
81
            + text.substring(end));
82
        getIntextReferences().add(intextReference);
83
        return intextReference;
84
    }
85

  
66 86
	@Override
67 87
    public void addIntextReference(IntextReference intextReference){
68 88
		if (intextReference != null){
69
			intextReference.setLanguageString(this);
89
			intextReference.setReferencedEntity(this);
70 90
			getIntextReferences().add(intextReference);
71 91
		}
72 92
	}
......
75 95
    public void removeIntextReference(IntextReference intextReference){
76 96
		if(getIntextReferences().contains(intextReference)) {
77 97
			getIntextReferences().remove(intextReference);
78
			intextReference.setLanguageString(null);
98
			intextReference.setReferencedEntity(null);
79 99
		}
80 100
	}
81 101

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/Media.java
49 49
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
50 50
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
51 51
import eu.etaxonomy.cdm.model.agent.AgentBase;
52
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
52 53
import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder;
53 54
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
54 55
import eu.etaxonomy.cdm.model.common.Language;
......
83 84
//@Indexed
84 85
@Audited
85 86
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
86
public class Media extends IdentifiableEntity<IIdentifiableEntityCacheStrategy> implements Cloneable, IMultiLanguageTextHolder {
87
public class Media extends IdentifiableEntity<IIdentifiableEntityCacheStrategy>
88
        implements IMultiLanguageTextHolder, IIntextReferenceTarget, Cloneable {
87 89
    private static final long serialVersionUID = -1927421567263473658L;
88 90
    @SuppressWarnings("unused")
89 91
    private static final Logger logger = Logger.getLogger(Media.class);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java
65 65
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
66 66
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
67 67
import eu.etaxonomy.cdm.model.common.CdmBase;
68
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
68 69
import eu.etaxonomy.cdm.model.common.IParsable;
69 70
import eu.etaxonomy.cdm.model.common.IRelated;
70 71
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
......
167 168
            extends IdentifiableEntity<S>
168 169
            implements ITaxonNameBase, INonViralName, IViralName, IBacterialName, IZoologicalName,
169 170
                IBotanicalName, ICultivarPlantName,
170
                IParsable, IRelated, IMatchable, Cloneable {
171
                IParsable, IRelated, IMatchable, IIntextReferenceTarget, Cloneable {
171 172

  
172 173
    private static final long serialVersionUID = -791164269603409712L;
173 174
    private static final Logger logger = Logger.getLogger(TaxonNameBase.class);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/Reference.java
50 50
import eu.etaxonomy.cdm.hibernate.search.DoiBridge;
51 51
import eu.etaxonomy.cdm.model.agent.Institution;
52 52
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
53
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
53 54
import eu.etaxonomy.cdm.model.common.TimePeriod;
54 55
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
55 56
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
......
122 123
        implements IArticle, IBook, IPatent, IDatabase, IJournal, IBookSection,ICdDvd,
123 124
                   IGeneric,IInProceedings, IProceedings, IPrintSeries, IReport,
124 125
                   IThesis,IWebPage, IPersonalCommunication,
125
                   INomenclaturalReference, IReference,
126
                   INomenclaturalReference, IReference, IIntextReferenceTarget,
126 127
                   Cloneable {
127 128

  
128 129
    private static final long serialVersionUID = -2034764545042691295L;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonBase.java
40 40
import eu.etaxonomy.cdm.common.CdmUtils;
41 41
import eu.etaxonomy.cdm.hibernate.search.AcceptedTaxonBridge;
42 42
import eu.etaxonomy.cdm.hibernate.search.ClassInfoBridge;
43
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
43 44
import eu.etaxonomy.cdm.model.common.IPublishable;
44 45
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
45 46
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
......
98 99
            impl = AcceptedTaxonBridge.class),
99 100
    @ClassBridge(impl = eu.etaxonomy.cdm.hibernate.search.NomenclaturalSortOrderBrigde.class)
100 101
})
101
public abstract class TaxonBase<S extends ITaxonCacheStrategy> extends IdentifiableEntity<S> implements  IPublishable, Cloneable {
102
public abstract class TaxonBase<S extends ITaxonCacheStrategy> extends IdentifiableEntity<S> implements  IPublishable, IIntextReferenceTarget, Cloneable {
102 103
    private static final long serialVersionUID = -3589185949928938529L;
103 104
    private static final Logger logger = Logger.getLogger(TaxonBase.class);
104 105

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/data/FullCoverageDataGenerator.java
340 340

  
341 341
		Taxon referencedTaxon = getTaxon();
342 342
		cdmBases.add(referencedTaxon);
343
		languageString.addIntextReference(IntextReference.NewTaxonInstance(referencedTaxon, languageString, 2, 5));
343
		languageString.addIntextReference(IntextReference.NewInstance(referencedTaxon, languageString, 2, 5));
344 344
		textData.putModifyingText(eng, "nice diagnosis");
345 345
		handleAnnotatableEntity(textData);
346 346
		handleAnnotatableEntity(languageString);
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DeduplicationHelper.java
40 40
import eu.etaxonomy.cdm.model.common.CdmBase;
41 41
import eu.etaxonomy.cdm.model.common.Extension;
42 42
import eu.etaxonomy.cdm.model.common.ICdmBase;
43
import eu.etaxonomy.cdm.model.common.IIntextReferencable;
43 44
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
44 45
import eu.etaxonomy.cdm.model.common.Identifier;
46
import eu.etaxonomy.cdm.model.common.IntextReference;
45 47
import eu.etaxonomy.cdm.model.common.Marker;
46 48
import eu.etaxonomy.cdm.model.name.BotanicalName;
47 49
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
......
425 427
				identifiableEntity1.addIdentifier(clone);
426 428
				removeListIdentifier.add(changeObject);
427 429
			} catch (CloneNotSupportedException e) {
428
				e.printStackTrace();
430
			    throw new RuntimeException(e);
429 431
			}
430 432
		}
431 433
		for (Identifier<?> removeObject : removeListIdentifier){
......
549 551
			if (!cloneSet.contains(referencingObject)){
550 552
		        String className = refHolder.otherClass.getSimpleName();
551 553
	            String propertyName = refHolder.propertyName;
552
		        String hql = "UPDATE " + className + " c SET c."+propertyName+" = :newValue WHERE c.id = :id";
554
		        String hql = " UPDATE " + className + " c "
555
		                + " SET c."+propertyName+" = :newValue "
556
		                + " WHERE c.id = :id ";
553 557
		        Query query = session.createQuery(hql);
554 558
		        query.setEntity("newValue", cdmBase1);
555 559
		        query.setInteger("id",referencingObject.getId());
556 560
		        int rowCount = query.executeUpdate();
557
		        logger.debug("Rows affected: " + rowCount);
561
		        if (logger.isDebugEnabled()){logger.debug("Rows affected: " + rowCount);}
558 562
		        session.refresh(referencingObject);
563
		        if (refHolder.otherClass == IntextReference.class){
564
		            IntextReference intextRef = CdmBase.deproxy(referencingObject, IntextReference.class);
565
		            IIntextReferencable refEnt = intextRef.getReferencedEntity();
566
		            if (refEnt != null) {
567
                        String newText = refEnt.getText() == null? null: refEnt.getText().replace(cdmBase2.getUuid().toString(), cdmBase1.getUuid().toString());
568
                        refEnt.setText(newText);
569
                        session.saveOrUpdate(refEnt);
570
                    }
571

  
572
		            //TODO
573
		            /*
574
		             * UPDATE LanguageString
575
		             * SET text = Replace(text, cdmBase2.getUuuid(), cdmBase1.getUuid)
576
		             * WHERE id IN (SELECT * FROM IntextReference
577
		             *
578
		             */
579
		            System.out.println("IntextReference found");
580
		        }
559 581
	        }
560 582
	    }
561 583
		session.flush();
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImplTest.java
120 120
import eu.etaxonomy.cdm.model.name.HybridRelationship;
121 121
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
122 122
import eu.etaxonomy.cdm.model.name.IBotanicalName;
123
import eu.etaxonomy.cdm.model.name.IZoologicalName;
124 123
import eu.etaxonomy.cdm.model.name.NameRelationship;
125 124
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
126 125
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
......
162 161
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;
163 162
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
164 163
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;
164
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
165 165
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
166 166
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
167 167
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
......
194 194
	@SpringBeanByType
195 195
	private IAgentDao agentDao;
196 196

  
197
    @SpringBeanByType
198
    private IReferenceDao referenceDao;
199

  
197 200
	/**
198 201
	 * @throws java.lang.Exception
199 202
	 */
......
821 824

  
822 825
    }
823 826

  
827
    @Test
828
    public void testReallocateIntextReference() throws MergeException {
829
        UUID uuidRef1 = UUID.fromString("41743cec-b893-4e8b-b06c-91f9b9ba8fee");
830
        UUID uuidRef2 = UUID.fromString("8fd56b43-7cca-4c3b-bb90-7576da81c072");
831

  
832
        Reference ref1 = ReferenceFactory.newGeneric();
833
        ref1.setTitle("Reference1");
834
        ref1.setUuid(uuidRef1);
835
        Reference ref2 = ReferenceFactory.newGeneric();
836
        ref2.setTitle("Reference2");
837
        ref2.setUuid(uuidRef2);
838
        referenceDao.save(ref2);
839

  
840
        TaxonNameBase<?,?> name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
841
        name1.setTitleCache("BotanicalName1", true);
842
        Taxon taxon = Taxon.NewInstance(name1, null);
843
        TaxonDescription desc = TaxonDescription.NewInstance(taxon);
844
        Language language = Language.DEFAULT();
845
        TextData textData = TextData.NewInstance(Feature.DESCRIPTION(), "And here is a citation" , language, null);
846
        LanguageString languageString = textData.getLanguageText(language);
847
        IntextReference intextRef = languageString.addIntextReference(ref1, 4, 8);
848
        String uuidIntextRef = intextRef.getUuid().toString();
849
        desc.addElement(textData);
850
        Assert.assertEquals("And <cdm:reference cdmId='"+ref1.getUuid()+"' intextId='"+uuidIntextRef+"'>here</cdm:reference> is a citation",
851
                    languageString.getText());
852
        taxonDao.save(taxon);
853

  
854
        commitAndStartNewTransaction(null);
855
        DefaultMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Reference.class);
824 856

  
857
        ref1 = referenceDao.findByUuid(ref1.getUuid());
858
        ref2 = referenceDao.findByUuid(ref2.getUuid());
859
        cdmGenericDao.merge(ref2, ref1, strategy);
860

  
861
        taxon = (Taxon)taxonDao.findByUuid(taxon.getUuid());
862
        textData = (TextData)taxon.getDescriptions().iterator().next().getElements().iterator().next();
863
        languageString = textData.getLanguageText(language);
864
        Assert.assertEquals("And <cdm:reference cdmId='"+ref2.getUuid()+"' intextId='"+uuidIntextRef+"'>here</cdm:reference> is a citation",
865
                languageString.getText());
866

  
867
    }
825 868

  
826 869
	/**
827 870
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmGenericDaoImpl#merge(CdmBase, CdmBase)}.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)