Project

General

Profile

Revision 45c1a780

ID45c1a78013e20762010e0a7d89bc6cbdb1126648
Parent 1402e210
Child 4bfde47a

Added by Andreas Müller almost 3 years ago

#5634 Add excludedNote to TaxonNode (still some tests not running)

View differences:

cdmlib-io/src/test/resources/eu/etaxonomy/cdm/database/ClearDBDataSet.xml
410 410
  <TAXONNODE_ANNOTATION/>
411 411
  <TAXONNODE_ANNOTATION_AUD/>
412 412
  <TAXONNODE_AUD/>
413
  <TAXONNODE_EXCLUDEDNOTE/>
414
  <TAXONNODE_EXCLUDEDNOTE_AUD/>
413 415
  <TAXONNODE_MARKER/>
414 416
  <TAXONNODE_MARKER_AUD/>
415 417
  <TAXONRELATIONSHIP/>
cdmlib-io/src/test/resources/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml
417 417
  <TAXONNODE_ANNOTATION/>
418 418
  <TAXONNODE_ANNOTATION_AUD/>
419 419
  <TAXONNODE_AUD/>
420
  <TAXONNODE_EXCLUDEDNOTE/>
421
  <TAXONNODE_EXCLUDEDNOTE_AUD/>
420 422
  <TAXONNODE_MARKER/>
421 423
  <TAXONNODE_MARKER_AUD/>
422 424
  <TAXONRELATIONSHIP/>
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
11 11
package eu.etaxonomy.cdm.model.taxon;
12 12

  
13 13
import java.util.ArrayList;
14
import java.util.HashMap;
14 15
import java.util.HashSet;
15 16
import java.util.List;
17
import java.util.Map;
16 18
import java.util.Set;
17 19

  
18 20
import javax.persistence.Column;
19 21
import javax.persistence.Entity;
20 22
import javax.persistence.FetchType;
23
import javax.persistence.JoinTable;
21 24
import javax.persistence.ManyToOne;
25
import javax.persistence.MapKeyJoinColumn;
22 26
import javax.persistence.OneToMany;
23 27
import javax.persistence.OrderBy;
24 28
import javax.persistence.OrderColumn;
......
32 36
import javax.xml.bind.annotation.XmlRootElement;
33 37
import javax.xml.bind.annotation.XmlSchemaType;
34 38
import javax.xml.bind.annotation.XmlType;
39
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
35 40

  
36 41
import org.apache.log4j.Logger;
37 42
import org.hibernate.LazyInitializationException;
......
45 50

  
46 51
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
47 52
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
53
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
48 54
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
49 55
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
50 56
import eu.etaxonomy.cdm.model.common.CdmBase;
51 57
import eu.etaxonomy.cdm.model.common.DefinedTerm;
52 58
import eu.etaxonomy.cdm.model.common.ITreeNode;
59
import eu.etaxonomy.cdm.model.common.Language;
60
import eu.etaxonomy.cdm.model.common.LanguageString;
53 61
import eu.etaxonomy.cdm.model.name.Rank;
54 62
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
55 63
import eu.etaxonomy.cdm.model.reference.Reference;
......
74 82
    "microReferenceForParentChildRelation",
75 83
    "countChildren",
76 84
    "agentRelations",
77
    "synonymToBeUsed"
85
    "synonymToBeUsed",
86
    "excludedNote"
78 87
})
79 88
@XmlRootElement(name = "TaxonNode")
80 89
@Entity
......
129 138
    @OrderBy("sortIndex")
130 139
    @OneToMany(mappedBy="parent", fetch=FetchType.LAZY)
131 140
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
132
    private List<TaxonNode> childNodes = new ArrayList<TaxonNode>();
141
    private List<TaxonNode> childNodes = new ArrayList<>();
133 142

  
134 143
    //see https://dev.e-taxonomy.eu/trac/ticket/3722
135 144
    //see https://dev.e-taxonomy.eu/trac/ticket/4200
......
154 163
    @XmlSchemaType(name = "IDREF")
155 164
    @OneToMany(mappedBy="taxonNode", fetch=FetchType.LAZY)
156 165
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
157
    private Set<TaxonNodeAgentRelation> agentRelations = new HashSet<TaxonNodeAgentRelation>();
166
    private Set<TaxonNodeAgentRelation> agentRelations = new HashSet<>();
158 167

  
159 168
    @XmlAttribute(name= "unplaced")
160 169
    private boolean unplaced = false;
......
166 175
    public boolean isExcluded() {return excluded;}
167 176
    public void setExcluded(boolean excluded) {this.excluded = excluded;}
168 177

  
169
//    @XmlElement(name = "microReference")
170
//    private String excludedNote;  ==>?? Multi-Lingual?
178
    @XmlElement(name = "excludedNote")
179
    @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
180
    @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
181
    @MapKeyJoinColumn(name="excludedNote_mapkey_id")
182
    @JoinTable(name = "TaxonNode_ExcludedNote")  //to make possible to add also unplacedNote
183
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE})
184
    private Map<Language,LanguageString> excludedNote = new HashMap<>();
171 185

  
172 186
//	private Taxon originalConcept;
173 187
//	//or
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/LanguageStringTableCreator.java
1
/**
2
 *
3
 */
4
package eu.etaxonomy.cdm.database.update;
5

  
6
/**
7
 * @author a.mueller
8
 *
9
 */
10
public class LanguageStringTableCreator extends MapTableCreator {
11

  
12
	public static LanguageStringTableCreator NewLanguageStringInstance(String stepName, String tableName, String attributeName, boolean includeAudTable){
13
		LanguageStringTableCreator result = new LanguageStringTableCreator(stepName, tableName, tableName, attributeName, includeAudTable);
14
		return result;
15
	}
16

  
17

  
18
	protected LanguageStringTableCreator(String stepName, String firstTableName, String firstTableAlias, String attributeName, boolean includeAudTable) {
19
		super(stepName, firstTableName, firstTableAlias, "LanguageString", attributeName, "DefinedTermBase", includeAudTable);
20
	}
21

  
22
//	@Override
23
//    protected String primaryKey(boolean isAudit){
24
//		String result = "";
25
//		if (! isAudit){
26
//			result = getFirstIdColumn() + ",";
27
//			result += getMapKeyColumn() + ",";
28
//		}else{
29
//			result = "REV, " + primaryKey(false) + ",";
30
//			result += getSecondIdColumn() + ",";
31
//		}
32
//		result = StringUtils.chomp(result.trim(), ",");
33
//		return result;
34
//	}
35

  
36
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/MapTableCreator.java
1 1
/**
2
 * 
2
 *
3 3
 */
4 4
package eu.etaxonomy.cdm.database.update;
5 5

  
......
13 13
 */
14 14
public class MapTableCreator extends TableCreator {
15 15

  
16
	private String firstTableName;
16
    private String firstTableName;
17 17
	private String firstTableAlias;
18
	private String secondTableAlias;
19 18
	private String secondTableName;
19
	private String secondTableAlias;
20 20
	private String mapKeyTableName;
21
	
21

  
22 22
	public static MapTableCreator NewMapTableInstance(String stepName, String firstTableName, String firstTableAlias, String secondTableName, String secondTableAlias, String mapKeyTableName, boolean includeAudTable){
23 23
		MapTableCreator result = new MapTableCreator(stepName, firstTableName, firstTableAlias, secondTableName, secondTableAlias, mapKeyTableName, includeAudTable);
24 24
		return result;
25 25
	}
26 26

  
27
	
27

  
28 28
	protected MapTableCreator(String stepName, String firstTableName, String firstTableAlias, String secondTableName, String secondTableAlias, String mapKeyTableName, boolean includeAudTable) {
29
		super(stepName, firstTableName + "_" + secondTableName, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<Object>(), new ArrayList<Boolean>(), new ArrayList<String>(), includeAudTable, false, false, false, false);
30
		this.firstTableName = firstTableName;
31
		this.secondTableName = secondTableName;
32
		this.firstTableAlias = (firstTableAlias != null )? firstTableAlias : firstTableName ;
33
		this.secondTableAlias = (secondTableAlias !=  null)? secondTableAlias : secondTableName ;
34
		this.mapKeyTableName = mapKeyTableName;
35
		addMyColumns();
29
		this(stepName,  firstTableName + "_" + StringUtils.capitalise(secondTableAlias), firstTableName, firstTableAlias, secondTableName, secondTableAlias, mapKeyTableName, includeAudTable);
36 30
	}
37 31

  
38
	
32
	   protected MapTableCreator(String stepName, String MN_tableName, String firstTableName, String firstTableAlias, String secondTableName, String secondTableAlias, String mapKeyTableName, boolean includeAudTable) {
33
	        super(stepName, MN_tableName, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<Object>(), new ArrayList<Boolean>(), new ArrayList<String>(), includeAudTable, false, false, false, false);
34
	        this.firstTableName = firstTableName;
35
	        this.secondTableName = secondTableName;
36
	        this.firstTableAlias = (firstTableAlias != null )? firstTableAlias : firstTableName ;
37
	        this.secondTableAlias = (secondTableAlias !=  null)? secondTableAlias : secondTableName ;
38
	        this.mapKeyTableName = mapKeyTableName;
39
	        addMyColumns();
40
	    }
41

  
42

  
39 43
	protected void addMyColumns(){
40 44
		this.columnAdders.add(ColumnAdder.NewIntegerInstance(stepName, tableName, getFirstIdColumn(), false, true, firstTableName));
41 45
		this.columnAdders.add(ColumnAdder.NewIntegerInstance(stepName, tableName, getSecondIdColumn(), false, true, secondTableName));
42 46
		this.columnAdders.add(ColumnAdder.NewIntegerInstance(stepName, tableName, getMapKeyColumn(), false, true, mapKeyTableName));
43 47
	}
44 48

  
49
	@Override
45 50
	protected String primaryKey(boolean isAudit){
46 51
		String result = "";
47 52
		if (! isAudit){
......
54 59
		result = StringUtils.chomp(result.trim(), ",");
55 60
		return result;
56 61
	}
57
	
58
	protected String unique(boolean isAudit){
62

  
63
	@Override
64
    protected String unique(boolean isAudit){
59 65
		if (! isAudit){
60 66
			return getSecondIdColumn();
61 67
		}else{
62 68
			return null;
63 69
		}
64 70
	}
65
	
71

  
66 72
	private String getFirstIdColumn(){
67 73
		return this.firstTableAlias + "_id";
68 74
	}
69
	
75

  
70 76
	private String getSecondIdColumn(){
71 77
		String result = this.secondTableAlias.toLowerCase();
72
		
78

  
73 79
		if (this.secondTableAlias.equalsIgnoreCase(this.secondTableName) ){
74 80
			if (! result.endsWith("s")){
75 81
				result += "s";
......
78 84
		result += "_id";
79 85
		return result;
80 86
	}
81
	
87

  
82 88
	private String getMapKeyColumn(){
83 89
		String result = getSecondIdColumn();
84 90
		result = result.replace("_id", "_mapkey_id");
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v40_41/SchemaUpdater_40_41.java
20 20
import eu.etaxonomy.cdm.database.update.ColumnRemover;
21 21
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
22 22
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
23
import eu.etaxonomy.cdm.database.update.IndexAdder;
24
import eu.etaxonomy.cdm.database.update.LanguageStringTableCreator;
23 25
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
24 26
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
25 27
import eu.etaxonomy.cdm.database.update.SortIndexUpdater;
......
243 245
        step = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, updateSql, nonAuditedTableName, -99);
244 246
        stepList.add(step);
245 247

  
246
        //#5981  Add abbreviation to idInVoc for 'Cultivar
248
        //#5981  Add abbreviation to idInVoc for 'Cultivar'
247 249
        stepName = "#5981 Add abbreviation to idInVoc for 'Cultivar'";
248 250
        updateSql = "UPDATE DefinedTermBase SET idInVocabulary='cv.' WHERE uuid='5e98415b-dc6e-440b-95d6-ea33dbb39ad0'";
249 251
        nonAuditedTableName = "DefinedTermBase";
......
263 265
        step = ColumnAdder.NewBooleanInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT, false);
264 266
        stepList.add(step);
265 267

  
268
        //#5634 Add excluded note
269
        stepName = "Add excluded note";
270
        tableName = "TaxonNode";
271
        String attributeName = "excludedNote";
272
        step = LanguageStringTableCreator.NewLanguageStringInstance(stepName, tableName, attributeName, INCLUDE_AUDIT);
273
        stepList.add(step);
274

  
266 275
        return stepList;
267 276
    }
268 277

  
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml
419 419
  <TAXONNODE_ANNOTATION/>
420 420
  <TAXONNODE_ANNOTATION_AUD/>
421 421
  <TAXONNODE_AUD/>
422
  <TAXONNODE_EXCLUDEDNOTE/>
423
  <TAXONNODE_EXCLUDEDNOTE_AUD/>
422 424
  <TAXONNODE_MARKER/>
423 425
  <TAXONNODE_MARKER_AUD/>
424 426
  <TAXONRELATIONSHIP/>
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml
419 419
  <TAXONNODE_ANNOTATION/>
420 420
  <TAXONNODE_ANNOTATION_AUD/>
421 421
  <TAXONNODE_AUD/>
422
  <TAXONNODE_EXCLUDEDNOTE/>
423
  <TAXONNODE_EXCLUDEDNOTE_AUD/>
422 424
  <TAXONNODE_MARKER/>
423 425
  <TAXONNODE_MARKER_AUD/>
424 426
  <TAXONRELATIONSHIP/>
cdmlib-test/src/main/resources/dbscripts/001-cdm.h2.sql
4615 4615
    REVTYPE TINYINT
4616 4616
);
4617 4617
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.TAXONNODE_ANNOTATION_AUD;
4618
CREATE CACHED TABLE PUBLIC.TAXONNODE_EXCLUDEDNOTE(
4619
    TAXONNODE_ID INTEGER NOT NULL,
4620
    EXCLUDEDNOTE_ID INTEGER NOT NULL,
4621
	EXCLUDEDNOTE_MAPKEY_ID INTEGER NOT NULL
4622
);
4623
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.TAXONNODE_EXCLUDEDNOTE;
4624
CREATE CACHED TABLE PUBLIC.TAXONNODE_EXCLUDEDNOTE_AUD(
4625
    REV INTEGER NOT NULL,
4626
    TAXONNODE_ID INTEGER NOT NULL,
4627
    EXCLUDEDNOTE_ID INTEGER NOT NULL,
4628
	EXCLUDEDNOTE_MAPKEY_ID INTEGER NOT NULL,
4629
    REVTYPE TINYINT
4630
);
4631
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.TAXONNODE_EXCLUDEDNOTE_AUD;
4618 4632
CREATE CACHED TABLE PUBLIC.TAXONNODE_MARKER(
4619 4633
    TAXONNODE_ID INTEGER NOT NULL,
4620 4634
    MARKERS_ID INTEGER NOT NULL
cdmlib-test/src/main/resources/eu/etaxonomy/cdm/database/ClearDBDataSet.xml
409 409
  <TAXONNODE_ANNOTATION/>
410 410
  <TAXONNODE_ANNOTATION_AUD/>
411 411
  <TAXONNODE_AUD/>
412
  <TAXONNODE_EXCLUDEDNOTE/>
413
  <TAXONNODE_EXCLUDEDNOTE_AUD/>
412 414
  <TAXONNODE_MARKER/>
413 415
  <TAXONNODE_MARKER_AUD/>
414 416
  <TAXONRELATIONSHIP/>
cdmlib-test/src/main/resources/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml
419 419
  <TAXONNODE_ANNOTATION/>
420 420
  <TAXONNODE_ANNOTATION_AUD/>
421 421
  <TAXONNODE_AUD/>
422
  <TAXONNODE_EXCLUDEDNOTE/>
423
  <TAXONNODE_EXCLUDEDNOTE_AUD/>
422 424
  <TAXONNODE_MARKER/>
423 425
  <TAXONNODE_MARKER_AUD/>
424 426
  <TAXONRELATIONSHIP/>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)