Project

General

Profile

Revision 64cf9d1d

ID64cf9d1d9ccdebd67a000f3f6298a52b3c4b690e
Parent 320dfcf7
Child f4e9f32a

Added by Andreas Müller over 1 year ago

ref #6794 fix early setting of termType during term loading

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/DefinedTermBase.java
393 393

  
394 394

  
395 395
    @Override
396
    public T readCsvLine(Class<T> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
396
    public T readCsvLine(Class<T> termClass, List<String> csvLine, TermType termType, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
397 397
        try {
398
            T newInstance = getInstance(termClass);
398
            T newInstance = getInstance(termClass, termType);
399 399
            readCsvLine(newInstance, csvLine, Language.CSV_LANGUAGE(), abbrevAsId);
400 400
            readIsPartOf(newInstance, csvLine, terms);
401 401
            return newInstance;
......
448 448
    }
449 449

  
450 450

  
451
    private  <T extends DefinedTermBase> T getInstance(Class<? extends DefinedTermBase> termClass) {
451
    private  <T extends DefinedTermBase> T getInstance(Class<? extends DefinedTermBase> termClass, TermType termType) {
452 452
        try {
453 453
            Constructor<T> c = ((Class<T>)termClass).getDeclaredConstructor();
454 454
            c.setAccessible(true);
455 455
            T termInstance = c.newInstance();
456
            termInstance.setTermType(termType);
456 457
            return termInstance;
457 458
        } catch (Exception e) {
458 459
            throw new RuntimeException(e);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ILoadableTerm.java
22 22
	 * the csvLine attributes are merged into the existing default language and the default Language is returned.
23 23
	 * @return
24 24
	 */
25
	public T readCsvLine(Class<T> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId);
25
	public T readCsvLine(Class<T> termClass, List<String> csvLine, TermType termType, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId);
26 26

  
27 27
	public  void writeCsvLine(CSVWriter writer, T term);
28 28
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Language.java
1201 1201
//    }
1202 1202

  
1203 1203
    @Override
1204
    public Language readCsvLine(Class<Language> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
1204
    public Language readCsvLine(Class<Language> termClass, List<String> csvLine, TermType termType, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
1205 1205
        try {
1206
            Language newInstance =  Language.class.newInstance();
1206
            Language newInstance =  Language.NewInstance();  //term type not needed is added in constructor anyway
1207 1207
            if ( UUID.fromString(csvLine.get(0).toString()).equals(Language.uuidEnglish)){
1208 1208
                DefinedTermBase.readCsvLine(newInstance, csvLine, newInstance, abbrevAsId);
1209 1209
            }else{
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/RelationshipTermBase.java
244 244
//**************** CSV *************************/
245 245

  
246 246
	@Override
247
	public T readCsvLine(Class<T> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
248
		T newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
247
	public T readCsvLine(Class<T> termClass, List<String> csvLine, TermType termType, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
248
		T newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
249 249

  
250 250
		String inverseText = CdmUtils.Ne(csvLine.get(6).trim());
251 251
		String inverseLabel = csvLine.get(5).trim();
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/TermLoader.java
142 142
			Class<? extends DefinedTermBase> termClass,
143 143
			TermVocabulary<T> voc, boolean abbrevAsId,
144 144
			T classDefiningTermInstance) {
145
		T term = (T) classDefiningTermInstance.readCsvLine(termClass,arrayedLine(csvLine), terms, abbrevAsId);
146
		term.setTermType(voc.getTermType());
145
		T term = (T) classDefiningTermInstance.readCsvLine(termClass,arrayedLine(csvLine), voc.getTermType(), terms, abbrevAsId);
147 146
		voc.addTerm(term);
148 147
		terms.put(term.getUuid(), term);
149 148
		return term;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/Feature.java
655 655
	 * @see     		#NewInstance(String, String, String)
656 656
	 */
657 657
	@Override
658
	public Feature readCsvLine(Class<Feature> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
659
		Feature newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
658
	public Feature readCsvLine(Class<Feature> termClass, List<String> csvLine, TermType termType,
659
	        Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
660
		Feature newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
660 661
		String text = csvLine.get(4);
661 662
		if (text != null && text.length() >= 6){
662 663
			if ("1".equals(text.substring(0, 1))){newInstance.setSupportsTextData(true);}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/PresenceAbsenceTerm.java
607 607
	}
608 608

  
609 609
    @Override
610
    public PresenceAbsenceTerm readCsvLine(Class<PresenceAbsenceTerm> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId){
611
    	PresenceAbsenceTerm newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
610
    public PresenceAbsenceTerm readCsvLine(Class<PresenceAbsenceTerm> termClass, List<String> csvLine, TermType termType,
611
            Map<UUID,DefinedTermBase> terms, boolean abbrevAsId){
612
    	PresenceAbsenceTerm newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
612 613
        String abbreviatedLabel = csvLine.get(4);
613 614
//		String uuid = (String)csvLine.get(0);
614 615
//		map.put(abbreviatedLabel, UUID.fromString(uuid));
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/Country.java
41 41
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
42 42
import eu.etaxonomy.cdm.model.common.Language;
43 43
import eu.etaxonomy.cdm.model.common.Representation;
44
import eu.etaxonomy.cdm.model.common.TermType;
44 45
import eu.etaxonomy.cdm.model.common.TermVocabulary;
45 46

  
46 47
/**
......
590 591
  	//for hibernate use only
591 592
  	@Deprecated
592 593
  	protected Country() {
594
  	    super(); //sets the term type to TermType.NamedAreas
593 595
	}
594 596
	private Country(String term, String label, String labelAbbrev) {
595 597
		super(term, label, labelAbbrev);
......
626 628
	}
627 629

  
628 630
	@Override
629
	public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
631
	public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, TermType termType,
632
	        Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
630 633
		try {
631 634
			Language lang= Language.DEFAULT();
632
			Country newInstance = Country.class.newInstance();
635
			Country newInstance = NewInstance();
633 636
			newInstance.setUuid(UUID.fromString(csvLine.get(0)));
634 637
			String uriStr = CdmUtils.Ne(csvLine.get(1));
635 638
	        newInstance.setUri(uriStr == null? null: URI.create(uriStr));
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/NamedArea.java
340 340
    }
341 341

  
342 342
    @Override
343
    public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
344
        NamedArea newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
343
    public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, TermType termType,
344
            Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
345
        NamedArea newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
345 346

  
346 347
        String levelString = csvLine.get(6);
347 348

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationshipType.java
508 508
	}
509 509

  
510 510
	@Override
511
	public NameRelationshipType readCsvLine(Class<NameRelationshipType> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
512
		NameRelationshipType result = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
511
	public NameRelationshipType readCsvLine(Class<NameRelationshipType> termClass, List<String> csvLine, TermType termType,
512
	        Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
513
		NameRelationshipType result = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
513 514
		String kindOfString = csvLine.get(10).trim();
514 515
		if (StringUtils.isNotBlank(kindOfString)){
515 516
			UUID uuidKindOf = UUID.fromString(kindOfString);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NomenclaturalStatusType.java
913 913
	 */
914 914

  
915 915
	@Override
916
    public NomenclaturalStatusType readCsvLine(Class<NomenclaturalStatusType> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {   //TODO should be List<String> but makes error for some strange reason
916
    public NomenclaturalStatusType readCsvLine(Class<NomenclaturalStatusType> termClass, List<String> csvLine, TermType termType,
917
            Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {   //TODO should be List<String> but makes error for some strange reason
917 918
		try {
918 919
			NomenclaturalStatusType newInstance = termClass.newInstance();
920
			newInstance.setTermType(termType);
919 921
			DefinedTermBase.readCsvLine(newInstance, csvLine, Language.LATIN(), abbrevAsId);
920 922
			return newInstance;
921 923
		} catch (Exception e) {
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/Rank.java
993 993

  
994 994

  
995 995
    @Override
996
    public Rank readCsvLine(Class<Rank> termClass, List<String> csvLine, Map<UUID, DefinedTermBase> terms, boolean abbrevAsId) {
997
        Rank rank = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
996
    public Rank readCsvLine(Class<Rank> termClass, List<String> csvLine, TermType termType, Map<UUID, DefinedTermBase> terms, boolean abbrevAsId) {
997
        Rank rank = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
998 998
        RankClass rankClass = RankClass.getByKey(csvLine.get(5));
999 999
        assert rankClass != null: "XXXXXXXXXXXXXXXXXXXXX  Rank class must not be null: " + csvLine ;
1000 1000
        rank.setRankClass(rankClass);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonRelationshipType.java
625 625
	}
626 626

  
627 627
    @Override
628
    public TaxonRelationshipType readCsvLine(Class<TaxonRelationshipType> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
629
        TaxonRelationshipType newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
628
    public TaxonRelationshipType readCsvLine(Class<TaxonRelationshipType> termClass, List<String> csvLine, TermType termType,
629
            Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
630
        TaxonRelationshipType newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
630 631

  
631 632
        newInstance.setSymbol(newInstance.getIdInVocabulary());
632 633
        String inverseLabelAbbrev = csvLine.get(7).trim();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)