Project

General

Profile

Revision 4afd76e7

ID4afd76e7642b5d023dfb9a07bad56d5c05072c81
Parent e46ded05
Child 8947f698

Added by Andreas Müller about 3 years ago

fix #6472 add key as target for IntextReference

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IntextReference.java
19 19
import org.hibernate.envers.Audited;
20 20

  
21 21
import eu.etaxonomy.cdm.model.agent.AgentBase;
22
import eu.etaxonomy.cdm.model.description.PolytomousKey;
22 23
import eu.etaxonomy.cdm.model.media.Media;
23 24
import eu.etaxonomy.cdm.model.name.TaxonName;
24 25
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
......
47 48
    "agent",
48 49
    "reference",
49 50
    "media",
51
    "key",
50 52
    "languageString",
51 53
    "annotation",
52 54
    "startPos",
......
94 96
    @ManyToOne(fetch = FetchType.LAZY)
95 97
	private Media media;
96 98

  
99
    @XmlElement(name = "SingleAccessKey")
100
    @XmlIDREF
101
    @XmlSchemaType(name = "IDREF")
102
    @ManyToOne(fetch = FetchType.LAZY)
103
    private PolytomousKey key;
104

  
105

  
97 106
    //TODO or do we want to link to LanguageString Base??
98 107
    @XmlElement(name = "LanguageString")
99 108
    @XmlIDREF
......
119 128
        AGENT("agent"),
120 129
        MEDIA("media"),
121 130
        OCCURRENCE("occurrence"),
122
        TAXON("taxon")
131
        TAXON("taxon"),
132
        KEY("key")
123 133
        ;
124 134
        String tag;
125 135

  
......
142 152
        return result;
143 153
    }
144 154

  
145
//	public static IntextReference NewTaxonNameInstance(TaxonName 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 155

  
169 156
	public static LanguageString NewReferencedLanguageString(IIntextReferenceTarget target, String pre, String middle, String post, Language language){
170 157
        LanguageString result = LanguageString.NewInstance(null, language);
......
195 182
	@Deprecated //for hibernate use only
196 183
	private IntextReference(){}
197 184

  
198
//	private IntextReference(TaxonName 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 185
	   private IntextReference(IIntextReferenceTarget target, IIntextReferencable referencedEntity, int start, int end) {
220 186
           super();
221 187
           setTarget(target);
......
239 205
            return CDM_INTEXT_CLASS.REFERENCE;
240 206
        }else if (occurrence != null){
241 207
            return CDM_INTEXT_CLASS.OCCURRENCE;
208
        }else if (key != null){
209
            return CDM_INTEXT_CLASS.KEY;
242 210
        }else{
243 211
            throw new IllegalStateException("Intext reference has no target object defined");
244 212
        }
......
265 233
           return reference;
266 234
       }else if (occurrence != null){
267 235
           return occurrence;
236
       }else if (key != null){
237
           return key;
268 238
       }else{
269 239
           throw new IllegalStateException("Intext reference has no target object defined");
270 240
       }
......
287 257
            this.reference = (Reference)target;
288 258
        }else if (target instanceof Media){
289 259
            this.media = (Media)target;
260
        }else if (target instanceof PolytomousKey){
261
            this.key = (PolytomousKey)target;
290 262
        }else{
291 263
            throw new IllegalArgumentException("Target entity not yet handled: " + target.getClass().getName());
292 264
        }
......
328 300
       }
329 301
   }
330 302

  
331
//	public TaxonName getTaxonName() {
332
//		return taxonName;
333
//	}
334
//	public void setTaxonName(TaxonName 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
//	}
388

  
389 303
	public int getStartPos() {
390 304
		return startPos;
391 305
	}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/PolytomousKey.java
37 37

  
38 38
import eu.etaxonomy.cdm.common.CdmUtils;
39 39
import eu.etaxonomy.cdm.model.common.DefinedTerm;
40
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
40 41
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
41 42
import eu.etaxonomy.cdm.model.common.Language;
42 43
import eu.etaxonomy.cdm.model.location.NamedArea;
......
74 75
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
75 76
//@Indexed(index = "eu.etaxonomy.cdm.model.description.PolytomousKey")
76 77
@Audited
77
public class PolytomousKey extends IdentifiableEntity<PolytomousKeyDefaultCacheStrategy> implements IIdentificationKey {
78
public class PolytomousKey
79
            extends IdentifiableEntity<PolytomousKeyDefaultCacheStrategy>
80
            implements IIdentificationKey, IIntextReferenceTarget {
81

  
78 82
    private static final long serialVersionUID = -3368243754557343942L;
79 83
    private static final Logger logger = Logger.getLogger(PolytomousKey.class);
80 84

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v41_47/SchemaUpdater_41_47.java
23 23
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
24 24
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
25 25
import eu.etaxonomy.cdm.database.update.TableCreator;
26
import eu.etaxonomy.cdm.database.update.UniqueIndexDropper;
27 26
import eu.etaxonomy.cdm.database.update.TableNameChanger;
27
import eu.etaxonomy.cdm.database.update.UniqueIndexDropper;
28 28
import eu.etaxonomy.cdm.database.update.v40_41.SchemaUpdater_40_41;
29 29

  
30 30
/**
......
210 210
        step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, length, INCLUDE_AUDIT);
211 211
        stepList.add(step);
212 212

  
213
        //ModelUpdateResult
214

  
215
        //Remove termupdater and allow update only from version 4.0
216

  
213
        //#6472 add key to IntextReference
214
        stepName = "Add key to IntextReference";
215
        tableName = "IntextReference";
216
        newColumnName = "key_id";
217
        referencedTable = "PolytomousKey";
218
        step = ColumnAdder.NewIntegerInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
219
        stepList.add(step);
217 220

  
218 221

  
219 222
        return stepList;
......
368 371
        stepList.add(step);
369 372

  
370 373
        //#6368
371
        chnageTaxonNameTableName(stepList);
374
        changeTaxonNameTableName(stepList);
372 375

  
373 376
    }
374 377

  
375 378
    /**
376 379
     * #6368
377 380
     */
378
    private void chnageTaxonNameTableName(List<ISchemaUpdaterStep> stepList) {
381
    private void changeTaxonNameTableName(List<ISchemaUpdaterStep> stepList) {
379 382

  
380 383
        //Update
381 384
        String oldName = "TaxonNameBase";
cdmlib-test/src/main/resources/dbscripts/001-cdm.h2.sql
2240 2240
  	OCCURRENCE_ID INT,
2241 2241
  	REFERENCE_ID INT,
2242 2242
  	TAXON_ID INT,
2243
  	TAXONNAME_ID INT
2243
  	TAXONNAME_ID INT,
2244
	KEY_ID INT
2244 2245
);
2245 2246
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.INTEXTREFERENCE;
2246 2247
CREATE CACHED TABLE PUBLIC.INTEXTREFERENCE_AUD(
......
2261 2262
  	OCCURRENCE_ID INT,
2262 2263
  	REFERENCE_ID INT,
2263 2264
  	TAXON_ID INT,
2264
  	TAXONNAME_ID INT
2265
  	TAXONNAME_ID INT,
2266
	KEY_ID INT
2265 2267
);
2266 2268
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.INTEXTREFERENCE_AUD;
2267 2269

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)