Project

General

Profile

« Previous | Next » 

Revision 8bc5f53a

Added by Andreas Müller over 16 years ago

View differences:

.gitattributes
55 55
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Extension.java -text
56 56
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ExtensionType.java -text
57 57
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Figure.java -text
58
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ICdmBase.java -text
58 59
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IDefTerm.java -text
59 60
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IEvent.java -text
61
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ILoadableTerm.java -text
60 62
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IMediaDocumented.java -text
61 63
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IOriginalSource.java -text
62 64
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IReferencedEntity.java -text
.gitignore
1
/.metadata
1 2
cdmlib-commons/.classpath
2 3
cdmlib-commons/.project
3 4
cdmlib-commons/.settings
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/CdmBase.java
38 38
 *
39 39
 */
40 40
@MappedSuperclass
41
public abstract class CdmBase implements Serializable{
41
public abstract class CdmBase implements Serializable, ICdmBase{
42 42
	private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
43 43
	private int id;
44 44
	private UUID uuid;
......
107 107
		propertyChangeSupport.firePropertyChange(evt);
108 108
	}
109 109

  
110
	/**
111
	 * Returns local unique identifier for the concrete subclass
112
	 * @return
110
	/* (non-Javadoc)
111
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
113 112
	 */
114 113
	@Id
115 114
	@GeneratedValue(generator = "system-increment")
116 115
	public int getId() {
117 116
		return this.id;
118 117
	}
119
	/**
120
	 * Assigns a unique local ID to this object. 
121
	 * Because of the EJB3 @Id and @GeneratedValue annotation this id will be
122
	 * set automatically by the persistence framework when object is saved.
123
	 * @param id
118
	/* (non-Javadoc)
119
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
124 120
	 */
125 121
	public void setId(int id) {
126 122
		this.id = id;
......
144 140
	}
145 141
	
146 142
	
143
	/* (non-Javadoc)
144
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getUuid()
145
	 */
147 146
	@Transient
148 147
	public UUID getUuid() {
149 148
		return this.uuid;
150 149
	}
150
	/* (non-Javadoc)
151
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setUuid(java.util.UUID)
152
	 */
151 153
	public void setUuid(UUID uuid) {
152 154
		this.uuid = uuid;
153 155
	}
154 156

  
155 157
	
158
	/* (non-Javadoc)
159
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreated()
160
	 */
156 161
	@Temporal(TemporalType.TIMESTAMP)
157 162
	@Basic(fetch = FetchType.LAZY)
158 163
	public Calendar getCreated() {
159 164
		return created;
160 165
	}
161
	/**
162
	 * Sets the timestamp this object was created. 
163
	 * Most databases cannot store milliseconds, so they are removed by this method.
164
	 * Caution: We are planning to replace the Calendar class with a different datetime representation which is more suitable for hibernate
165
	 * see {@link http://dev.e-taxonomy.eu/trac/ticket/247 TRAC ticket} 
166
	 * 
167
	 * @param created
166
	/* (non-Javadoc)
167
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreated(java.util.Calendar)
168 168
	 */
169 169
	public void setCreated(Calendar created) {
170 170
		if (created != null){
......
174 174
	}
175 175

  
176 176

  
177
	/* (non-Javadoc)
178
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreatedBy()
179
	 */
177 180
	@ManyToOne(fetch=FetchType.LAZY)
178 181
	@Cascade( { CascadeType.SAVE_UPDATE })
179 182
	public Person getCreatedBy() {
180 183
		return this.createdBy;
181 184
	}
185
	/* (non-Javadoc)
186
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreatedBy(eu.etaxonomy.cdm.model.agent.Person)
187
	 */
182 188
	public void setCreatedBy(Person createdBy) {
183 189
		this.createdBy = createdBy;
184 190
	}
......
193 199
		if (obj == null){
194 200
			return false;
195 201
		}else if (CdmBase.class.isAssignableFrom(obj.getClass())){
196
			CdmBase cdmObj = (CdmBase)obj;
202
			ICdmBase cdmObj = (ICdmBase)obj;
197 203
			boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
198 204
			boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
199 205
			if (uuidEqual && createdEqual){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/DefinedTermBase.java
37 37
 */
38 38
@Entity
39 39
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
40
public abstract class DefinedTermBase<T extends DefinedTermBase> extends TermBase implements IDefTerm{
40
public abstract class DefinedTermBase<T extends DefinedTermBase> extends TermBase implements ILoadableTerm{
41 41
	static Logger logger = Logger.getLogger(DefinedTermBase.class);
42 42
	
43 43
	static protected IVocabularyStore vocabularyStore = new DefaultVocabularyStore();
......
66 66
	}
67 67

  
68 68

  
69
	
69 70
	/* (non-Javadoc)
70
	 * @see eu.etaxonomy.cdm.model.common.IDefTerm#readCsvLine(java.util.List)
71
	 * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#readCsvLine(java.util.List)
71 72
	 */
72
	public void readCsvLine(List<String> csvLine) {
73
		readCsvLine(csvLine, Language.ENGLISH());
73
	public ILoadableTerm readCsvLine(List<String> csvLine) {
74
		return readCsvLine(csvLine, Language.ENGLISH());
74 75
	}
75
	public void readCsvLine(List<String> csvLine, Language lang) {
76
	public ILoadableTerm readCsvLine(List<String> csvLine, Language lang) {
76 77
		this.setUuid(UUID.fromString(csvLine.get(0)));
77 78
		this.setUri(csvLine.get(1));
78
		this.addRepresentation(new Representation(csvLine.get(3), csvLine.get(2).trim(), lang) );
79
		this.addRepresentation(Representation.NewInstance(csvLine.get(3), csvLine.get(2).trim(), lang) );
80
		return this;
79 81
	}
80 82

  
81 83
	/* (non-Javadoc)
82
	 * @see eu.etaxonomy.cdm.model.common.IDefTerm#writeCsvLine(au.com.bytecode.opencsv.CSVWriter)
84
	 * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#writeCsvLine(au.com.bytecode.opencsv.CSVWriter)
83 85
	 */
84 86
	public void writeCsvLine(CSVWriter writer) {
85 87
		String [] line = new String[4];
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ICdmBase.java
1
package eu.etaxonomy.cdm.model.common;
2

  
3
import java.util.Calendar;
4
import java.util.UUID;
5

  
6
import javax.persistence.Basic;
7
import javax.persistence.FetchType;
8
import javax.persistence.GeneratedValue;
9
import javax.persistence.Id;
10
import javax.persistence.ManyToOne;
11
import javax.persistence.Temporal;
12
import javax.persistence.TemporalType;
13
import javax.persistence.Transient;
14

  
15
import org.hibernate.annotations.Cascade;
16
import org.hibernate.annotations.CascadeType;
17

  
18
import eu.etaxonomy.cdm.model.agent.Person;
19

  
20
public interface ICdmBase {
21

  
22
	/**
23
	 * Returns local unique identifier for the concrete subclass
24
	 * @return
25
	 */
26
	@Id
27
	@GeneratedValue(generator = "system-increment")
28
	public abstract int getId();
29

  
30
	/**
31
	 * Assigns a unique local ID to this object. 
32
	 * Because of the EJB3 @Id and @GeneratedValue annotation this id will be
33
	 * set automatically by the persistence framework when object is saved.
34
	 * @param id
35
	 */
36
	public abstract void setId(int id);
37

  
38
	@Transient
39
	public abstract UUID getUuid();
40

  
41
	public abstract void setUuid(UUID uuid);
42

  
43
	@Temporal(TemporalType.TIMESTAMP)
44
	@Basic(fetch = FetchType.LAZY)
45
	public abstract Calendar getCreated();
46

  
47
	/**
48
	 * Sets the timestamp this object was created. 
49
	 * Most databases cannot store milliseconds, so they are removed by this method.
50
	 * Caution: We are planning to replace the Calendar class with a different datetime representation which is more suitable for hibernate
51
	 * see {@link http://dev.e-taxonomy.eu/trac/ticket/247 TRAC ticket} 
52
	 * 
53
	 * @param created
54
	 */
55
	public abstract void setCreated(Calendar created);
56

  
57
	@ManyToOne(fetch = FetchType.LAZY)
58
	@Cascade( { CascadeType.SAVE_UPDATE })
59
	public abstract Person getCreatedBy();
60

  
61
	public abstract void setCreatedBy(Person createdBy);
62

  
63
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ILoadableTerm.java
1
package eu.etaxonomy.cdm.model.common;
2

  
3
import java.util.List;
4

  
5
import javax.persistence.ManyToOne;
6

  
7
import org.hibernate.annotations.Cascade;
8
import org.hibernate.annotations.CascadeType;
9

  
10
import au.com.bytecode.opencsv.CSVWriter;
11

  
12
public interface ILoadableTerm extends ICdmBase{
13

  
14
	/**
15
	 * Fills the {@link ILoadableTerm} with contents from a csvLine. If the csvLine represents the default language
16
	 * the csvLine attributes are merged into the existing default language and the default Language is returned.
17
	 * @param csvLine
18
	 * @return
19
	 */
20
	public abstract ILoadableTerm readCsvLine(List<String> csvLine);
21

  
22
	public abstract void writeCsvLine(CSVWriter writer);
23

  
24
	@ManyToOne
25
	@Cascade( { CascadeType.SAVE_UPDATE })
26
	public abstract TermVocabulary getVocabulary();
27

  
28
	public abstract void setVocabulary(TermVocabulary newVocabulary);
29

  
30
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Language.java
45 45
	private static final UUID uuidDutch = UUID.fromString("9965d79a-acf9-4921-a2c0-863b8c16c056");
46 46
	private static final UUID uuidPolish = UUID.fromString("3fdca387-f1b0-4ec1-808f-1bc3dc482194");
47 47
	
48
	
48
	public static Language NewInstance(){
49
		return new Language();
50
	}
49 51
	
50 52
	private char[] iso639_1 = new char[2];
51 53
	private char[] iso639_2 = new char[3];
......
135 137
		return getUUID(uuidPolish);
136 138
	}
137 139
 
138
	public void readCsvLine(List csvLine) {
139
		// read UUID, URI, english label+description
140
		List<String> csvLineString = csvLine;
141
		super.readCsvLine(csvLine);
142
		// iso codes extra
143
		this.iso639_1=csvLineString.get(4).trim().toCharArray();
144
		this.iso639_2=csvLineString.get(5).trim().toCharArray();
140
	@Override 
141
	public ILoadableTerm readCsvLine(List csvLine) {
142
		ILoadableTerm result;
143
		if ( UUID.fromString(csvLine.get(0).toString()).equals(DEFAULT().getUuid()) && this != DEFAULT() ){
144
			result = DEFAULT();
145
			result.readCsvLine(csvLine);
146
		}else{
147
			// read UUID, URI, english label+description
148
			List<String> csvLineString = csvLine;
149
			result = this;
150
			super.readCsvLine(csvLine);
151
			// iso codes extra
152
			this.iso639_1=csvLineString.get(4).trim().toCharArray();
153
			this.iso639_2=csvLineString.get(5).trim().toCharArray();
154
		}
155
		return result;
145 156
	}
157
	
146 158
	public void writeCsvLine(CSVWriter writer) {
147 159
		String [] line = new String[6];
148 160
		line[0] = getUuid().toString();
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/RelationshipTermBase.java
129 129
		return this.getInverseRepresentation(lang).getDescription();
130 130
	}
131 131
	
132
	public void readCsvLine(List csvLine) {
132
	public ILoadableTerm readCsvLine(List csvLine) {
133
		RelationshipTermBase result;
133 134
		// read UUID, URI, english label+description
134 135
		List<String> csvLineString = (List<String>)csvLine;
135
		super.readCsvLine(csvLineString);
136
		result = (RelationshipTermBase)super.readCsvLine(csvLineString);
136 137
		// inverse label + 2 booleans
137
		this.addInverseRepresentation(new Representation(csvLineString.get(4).trim(), csvLineString.get(5).trim(), Language.ENGLISH()) );
138
		this.setSymmetric(Boolean.parseBoolean(csvLineString.get(6)));
139
		this.setTransitive(Boolean.parseBoolean(csvLineString.get(7)));
138
		result.addInverseRepresentation(new Representation(csvLineString.get(4).trim(), csvLineString.get(5).trim(), Language.ENGLISH()) );
139
		result.setSymmetric(Boolean.parseBoolean(csvLineString.get(6)));
140
		result.setTransitive(Boolean.parseBoolean(csvLineString.get(7)));
141
		return result;
140 142
	}
141 143
	
142 144
	public void writeCsvLine(CSVWriter writer) {
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Representation.java
28 28
	private String label;
29 29
	private String abbreviatedLabel;
30 30

  
31
	public static Representation NewInstance(String text, String label, Language lang){
32
		return new Representation(text, label, lang);
33
	}
34
	
31 35
	public Representation() {
32 36
		super();
33 37
	}	
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/DefaultVocabularyStore.java
11 11
import org.apache.log4j.Logger;
12 12

  
13 13
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
14
import eu.etaxonomy.cdm.model.common.ILoadableTerm;
14 15
import eu.etaxonomy.cdm.model.common.Language;
15 16
import eu.etaxonomy.cdm.model.common.TermVocabulary;
16 17

  
18
/**
19
 * @author AM
20
 *
21
 */
17 22
/**
18 23
 * @author AM
19 24
 *
......
28 33
	}
29 34
	
30 35
	
31
	static protected Map<UUID, DefinedTermBase> definedTermsMap = null;
36
	static protected Map<UUID, ILoadableTerm> definedTermsMap = null;
32 37
	static protected Map<UUID, TermVocabulary<DefinedTermBase>> termVocabularyMap = null;
33 38

  
34 39

  
35 40
	/* (non-Javadoc)
36 41
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#getTermByUuid(java.util.UUID)
37 42
	 */
38
	public DefinedTermBase getTermByUuid(UUID uuid) {
43
	public DefinedTermBase<DefinedTermBase> getTermByUuid(UUID uuid) {
39 44
		if (!isInitialized  &&  ! loadBasicTerms()){ return null;}
40
		return definedTermsMap.get(uuid);
45
		return (DefinedTermBase<DefinedTermBase>)definedTermsMap.get(uuid);
41 46
	}
42 47

  
43 48
	/* (non-Javadoc)
......
53 58
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#saveOrUpdate(eu.etaxonomy.cdm.model.common.TermVocabulary)
54 59
	 */
55 60
	public void saveOrUpdate(TermVocabulary<DefinedTermBase> vocabulary) {
61
		logger.info("dddd");
56 62
		loadBasicTerms();
57 63
		Iterator<DefinedTermBase> termIterator = vocabulary.iterator();
58

  
59 64
		while (termIterator.hasNext()){
60 65
			DefinedTermBase<DefinedTermBase> term = termIterator.next();
61 66
			if (definedTermsMap.get(term.getUuid()) != null){
......
66 71
		termVocabularyMap.put(vocabulary.getUuid(), vocabulary);
67 72
	}
68 73
	
74
	/* (non-Javadoc)
75
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#saveOrUpdate(eu.etaxonomy.cdm.model.common.TermVocabulary)
76
	 */
77
	public void saveOrUpdate(ILoadableTerm term) {
78
		loadBasicTerms();
79
		if (definedTermsMap.get(term.getUuid()) != null){
80
			term.setId(definedTermsMap.get(term.getUuid()).getId()); // to avoid duplicates in the default Language
81
		}
82
		definedTermsMap.put(term.getUuid(), term);
83
		termVocabularyMap.put(term.getVocabulary().getUuid(), term.getVocabulary());
84
	}
85
	
69 86
	
70 87
	public boolean loadBasicTerms() {
71 88
		if (definedTermsMap == null){
72 89
			logger.info("initTermsMap start ...");
73
			definedTermsMap = new HashMap<UUID, DefinedTermBase>();
90
			definedTermsMap = new HashMap<UUID, ILoadableTerm>();
74 91
			try {
75 92
				definedTermsMap.put(DEFAULT_LANGUAGE().getUuid(), DEFAULT_LANGUAGE());
76 93
				TermLoader termLoader = new TermLoader(this);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/IVocabularyStore.java
3 3
import java.util.UUID;
4 4

  
5 5
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
6
import eu.etaxonomy.cdm.model.common.ILoadableTerm;
6 7
import eu.etaxonomy.cdm.model.common.TermVocabulary;
7 8

  
8 9
/**
......
23 24
	 */
24 25
	public void saveOrUpdate(TermVocabulary<DefinedTermBase> vocabulary);
25 26
	
27
	
28
	
29
	/**
30
	 * TODO
31
	 * @param term
32
	 */
33
	public void saveOrUpdate(ILoadableTerm term);
34

  
35
	
26 36
	 /** ATTENTION: Be aware that TermLoader indirectly calls getTermByUuid(uuid)
27 37
	 * for the default language. So make sure that before loading the Terms by the
28 38
	 * TermLoader getTermByUuid() returns a valid Object without going to endless recursion.
29 39
	 * @param uuid the definedTermBases UUID
30 40
	 * @return the DefinedTermBase to return
31 41
	 */
32
	public DefinedTermBase getTermByUuid(UUID uuid);
42
	public DefinedTermBase<DefinedTermBase> getTermByUuid(UUID uuid);
33 43
	
34 44
	/**
35 45
	 * @param uuid
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/TermLoader.java
5 5
import java.io.InputStreamReader;
6 6
import java.util.ArrayList;
7 7
import java.util.HashMap;
8
import java.util.List;
9 8
import java.util.Map;
10 9
import java.util.UUID;
11 10

  
......
18 17
import eu.etaxonomy.cdm.common.CdmUtils;
19 18

  
20 19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.common.IDefTerm;
20
import eu.etaxonomy.cdm.model.common.ILoadableTerm;
22 21
import eu.etaxonomy.cdm.model.common.Language;
23 22
import eu.etaxonomy.cdm.model.common.NoDefinedTermClassException;
24 23
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
......
63 62
	// load a list of defined terms from a simple text file
64 63
	// if isEnumeration is true an Enumeration for the ordered term list will be returned
65 64
	@Transactional(readOnly = false)
66
	public TermVocabulary<DefinedTermBase> loadTerms(Class<IDefTerm> termClass, String filename, boolean isEnumeration, boolean isOrdered) throws NoDefinedTermClassException, FileNotFoundException {
65
	public TermVocabulary<DefinedTermBase> loadTerms(Class<ILoadableTerm> termClass, String filename, boolean isEnumeration, boolean isOrdered) throws NoDefinedTermClassException, FileNotFoundException {
67 66
		TermVocabulary voc;
68 67
		DefinedTermBase.setVocabularyStore(vocabularyStore); //otherwise DefinedTermBase is not able to find DefaultLanguage
69 68
		if (isOrdered){
......
71 70
		}else{
72 71
			voc = new TermVocabulary<DefinedTermBase>(termClass.getCanonicalName(), termClass.getSimpleName(), termClass.getCanonicalName());
73 72
		}
73
		logger.info("save vocabulary ...");
74
		saveVocabulary(voc, termClass);
75
		logger.info("save vocabulary end.");
74 76
		try {
75 77
			String strResourceFileName = "terms" + CdmUtils.getFolderSeperator() + filename;
76 78
			logger.debug("strResourceFileName is " + strResourceFileName);
......
81 83
			String [] nextLine;
82 84
			while ((nextLine = reader.readNext()) != null) {
83 85
				// nextLine[] is an array of values from the line
84
				IDefTerm term = termClass.newInstance();
85
				ArrayList<String> aList = new ArrayList<String>(10);
86
				ArrayList<String> csvTermAttributeList = new ArrayList<String>(10);
86 87
				for (String col : nextLine){
87
					aList.add(col);
88
					csvTermAttributeList.add(col);
88 89
				}
89
				while (aList.size()<10){
90
					aList.add("");
90
				while (csvTermAttributeList.size()<10){
91
					csvTermAttributeList.add("");
91 92
				}
92
				term.readCsvLine(aList);
93
				
94
				ILoadableTerm term = termClass.newInstance();
95
				term = term.readCsvLine(csvTermAttributeList);
93 96
				term.setVocabulary(voc);
97
				vocabularyStore.saveOrUpdate(term);
94 98
				// save enumeration and all terms to DB
95
				if (vocabularyStore != null){
96
					vocabularyStore.saveOrUpdate(voc);
97
				}else{
98
					//e.g. in tests when no database connection exists
99
					if (logger.isDebugEnabled()) {logger.debug("No vocabularyStore exists. Vocabulary for class '" + termClass +  "' could not be saved to database");}
100
				}
101 99
			}
102 100
		} catch (Exception e) {
103 101
			logger.error(e.getMessage());
104 102
		}
105 103
		return voc;
106 104
	}
105
	
106
	private void saveVocabulary(TermVocabulary voc, Class<ILoadableTerm> termClass){
107
		if (vocabularyStore != null){
108
			vocabularyStore.saveOrUpdate(voc);
109
		}else{
110
			//e.g. in tests when no database connection exists
111
			if (logger.isDebugEnabled()) {logger.debug("No vocabularyStore exists. Vocabulary for class '" + termClass +  "' could not be saved to database");}
112
		}
113

  
114
	}
107 115

  
108 116
	public TermVocabulary<DefinedTermBase> loadDefaultTerms(Class termClass, boolean isOrdered) throws NoDefinedTermClassException, FileNotFoundException {
109 117
		if (termClass != null){logger.info("load class " + termClass.getName());}
......
158 166
		if (saver == null){
159 167
			return false;
160 168
		}
161
		DefinedTermBase basicTerm = saver.getTermByUuid(uuid);
169
		ILoadableTerm basicTerm = saver.getTermByUuid(uuid);
162 170
		if ( basicTerm == null || ! basicTerm.getUuid().equals(uuid)){
163 171
			return false;
164 172
		}else{
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/WaterbodyOrCountry.java
11 11

  
12 12

  
13 13

  
14
import eu.etaxonomy.cdm.model.common.ILoadableTerm;
14 15
import eu.etaxonomy.cdm.model.common.Language;
15 16
import eu.etaxonomy.cdm.model.common.Representation;
16 17
import eu.etaxonomy.cdm.model.common.TimePeriod;
......
599 600
	}
600 601

  
601 602
	
602
	public void readCsvLine(List<String> csvLine) {
603
	public ILoadableTerm readCsvLine(List<String> csvLine) {
604
		ILoadableTerm result;
603 605
		// read UUID, URI, english label+description
604
		super.readCsvLine(csvLine);
606
		result = super.readCsvLine(csvLine);
605 607
		// iso codes extra
606 608
		this.iso2code=csvLine.get(4).trim();
609
		return result;
607 610
	}
608 611
	public void writeCsvLine(CSVWriter writer) {
609 612
		String [] line = new String[6];
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/view/View.java
13 13
import org.apache.log4j.Logger;
14 14

  
15 15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.common.ICdmBase;
16 17
import eu.etaxonomy.cdm.model.common.IReferencedEntity;
17 18
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
18 19

  
......
90 91
	public void addMember(CdmBase member) {
91 92
		this.members.add(member);
92 93
	}
93
	public void removeMember(CdmBase member) {
94
	public void removeMember(ICdmBase member) {
94 95
		this.members.remove(member);
95 96
	}
96 97

  
......
105 106
	public void addNonMember(CdmBase member) {
106 107
		this.nonMembers.add(member);
107 108
	}
108
	public void removeNonMember(CdmBase member) {
109
	public void removeNonMember(ICdmBase member) {
109 110
		this.nonMembers.remove(member);
110 111
	}
111 112

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/common/CdmBaseTest.java
507 507
	 */
508 508
	@Test
509 509
	public void testEqualsObject() {
510
		CdmBase cdmBase2 = getTestCdmBase();
510
		ICdmBase cdmBase2 = getTestCdmBase();
511 511
		cdmBase2.setUuid(cdmBase.getUuid());
512 512
		cdmBase2.setCreated(cdmBase.getCreated());
513 513
		cdmBase2.setCreatedBy(Person.NewInstance());
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/VocabularyStoreImpl.java
11 11
import org.apache.log4j.Logger;
12 12
import org.springframework.beans.factory.annotation.Autowired;
13 13
import org.springframework.stereotype.Component;
14
import org.springframework.transaction.annotation.Transactional;
15 14

  
16
import eu.etaxonomy.cdm.model.agent.Person;
17 15
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
16
import eu.etaxonomy.cdm.model.common.ILoadableTerm;
18 17
import eu.etaxonomy.cdm.model.common.Language;
19 18
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20 19
import eu.etaxonomy.cdm.model.common.init.IVocabularyStore;
......
26 25
 * @author a.mueller
27 26
 *
28 27
 */
28
/**
29
 * @author AM
30
 *
31
 */
29 32
@Component
30 33
public class VocabularyStoreImpl implements IVocabularyStore {
31 34
	private static Logger logger = Logger.getLogger(VocabularyStoreImpl.class);
......
36 39

  
37 40
	public static final Language DEFAULT_LANGUAGE= makeDefaultLanguage();
38 41
	private static Language makeDefaultLanguage() {
42
		logger.info("make Default language ...");
39 43
		Language defaultLanguage = new Language(uuidEnglish);
44
		logger.info("make Default language end");
40 45
		return defaultLanguage;
41 46
	}
42 47
	
43
	static protected Map<UUID, DefinedTermBase> definedTermsMap = null;
48
	static protected Map<UUID, ILoadableTerm> definedTermsMap = null;
44 49

  
45 50
	
46 51
	@Autowired
......
60 65
	/* (non-Javadoc)
61 66
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularySaver#saveOrUpdate(eu.etaxonomy.cdm.model.common.TermVocabulary)
62 67
	 */
63
	public void saveOrUpdate2(TermVocabulary<DefinedTermBase> vocabulary) {
68
	public void saveOrUpdate(TermVocabulary<DefinedTermBase> vocabulary) {
69
		logger.info("vocabulary save or update start ...");
64 70
		initialize();
65 71
		Iterator<DefinedTermBase> termIterator = vocabulary.iterator();
66 72
		while (termIterator.hasNext()){
73
			logger.info("iterate ...");
67 74
			DefinedTermBase<DefinedTermBase> term = termIterator.next();
68 75
			if (definedTermsMap.get(term.getUuid()) != null){
69 76
				term.setId(definedTermsMap.get(term.getUuid()).getId()); // to avoid duplicates in the default Language
70 77
			}
71 78
			definedTermsMap.put(term.getUuid(), term);
72 79
		}
80
		logger.info("vocabulary save or update before dao save ...");
73 81
		vocabularyDao.saveOrUpdate(vocabulary);
82
		logger.info("vocabulary save or update end.");
83
	}
84
	
85
	/* (non-Javadoc)
86
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#saveOrUpdate(eu.etaxonomy.cdm.model.common.IDefTerm)
87
	 */
88
	public void saveOrUpdate(ILoadableTerm term) {
89
		initialize();
90
		if (definedTermsMap.get(term.getUuid()) != null){
91
			ILoadableTerm oldTerm = definedTermsMap.get(term.getUuid());
92
			term.setId(oldTerm.getId()); // to avoid duplicates in the default Language
93
			
94
		}
95
		definedTermsMap.put(term.getUuid(), term);
96
//		vocabularyDao.saveOrUpdate(term);
74 97
	}
75 98

  
76
	public DefinedTermBase getTermByUuid(UUID uuid) {
99
	public DefinedTermBase<DefinedTermBase> getTermByUuid(UUID uuid) {
77 100
		if (initialize()){
78 101
			if (definedTermsMap.get(uuid) != null){
79
				return definedTermsMap.get(uuid);
102
				return (DefinedTermBase<DefinedTermBase>)definedTermsMap.get(uuid);
80 103
			}else{
81 104
				DefinedTermBase term = termDao.findByUuid(uuid);
82 105
				definedTermsMap.put(term.getUuid(), term);
......
101 124
		if (! initialized){
102 125
			logger.info("inititialize VocabularyStoreImpl ...");
103 126
			try {
127
				logger.info("000 ...");
104 128
				Language defaultLanguage = (Language)termDao.findByUuid(DEFAULT_LANGUAGE.getUuid());
105
				
129
				logger.info("aaa ...");
106 130
				if (defaultLanguage == null){
131
					logger.info("bbb ...");
132
					logger.info("DL ..."  + DEFAULT_LANGUAGE.hashCode());
107 133
					termDao.saveOrUpdate(DEFAULT_LANGUAGE);
108
					definedTermsMap = new HashMap<UUID, DefinedTermBase>();
134
					definedTermsMap = new HashMap<UUID, ILoadableTerm>();
109 135
					definedTermsMap.put(DEFAULT_LANGUAGE.getUuid(), DEFAULT_LANGUAGE);
136
					logger.info("ccc ...");
110 137
					initialized = true;
111 138
					TermLoader termLoader = new TermLoader(this);
112 139
					termLoader.loadAllDefaultTerms();
113 140
				}else if (definedTermsMap == null){
114
						definedTermsMap = new HashMap<UUID, DefinedTermBase>();
141
					logger.info("ddd ...");
142
					definedTermsMap = new HashMap<UUID, ILoadableTerm>();
115 143
						definedTermsMap.put(defaultLanguage.getUuid(), defaultLanguage);
116 144
				}
117 145
			} catch (Exception e) {
......
120 148
				return false;
121 149
			}
122 150
			initialized = true;
123
			logger.info("initTermsMap end ...");
151
			logger.info("inititialize VocabularyStoreImpl end ...");
124 152
		}
125 153
		return true;
126 154
	}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/CdmEntityDaoBase.java
8 8

  
9 9
import org.apache.log4j.Logger;
10 10
import org.hibernate.Criteria;
11
import org.hibernate.HibernateException;
12
import org.hibernate.NonUniqueObjectException;
11 13
import org.hibernate.Session;
12 14
import org.hibernate.criterion.Order;
13 15
import org.hibernate.criterion.Restrictions;
......
39 41
	}
40 42

  
41 43
	public UUID saveOrUpdate(T transientObject) throws DataAccessException  {
42
		Session session = getSession();
43
		session.saveOrUpdate(transientObject);
44
		return transientObject.getUuid();
44
		try {
45
			logger.info("dao saveOrUpdate start...");
46
			logger.info("transientObject(" + transientObject.getClass().getSimpleName() + ") ID:" + transientObject.getId() + ", UUID: " + transientObject.getUuid()) ;
47
			Session session = getSession();
48
			session.saveOrUpdate(transientObject);
49
			logger.info("dao saveOrUpdate edc");
50
			return transientObject.getUuid();
51
		} catch (NonUniqueObjectException e) {
52
			logger.error(e.getIdentifier());
53
			logger.error(e.getEntityName());
54
			logger.error(e.getMessage());
55
			e.printStackTrace();
56
			throw e;
57
		} catch (HibernateException e) {
58
			
59
			e.printStackTrace();
60
			throw e;
61
		}
45 62
	}
46 63

  
47 64
	public UUID save(T newInstance) throws DataAccessException {
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/CdmGenericDaoImpl.java
1 1
package eu.etaxonomy.cdm.persistence.dao.common;
2 2

  
3
import java.util.List;
4

  
5 3
import org.springframework.stereotype.Repository;
6
import org.springframework.transaction.annotation.Transactional;
7 4

  
8 5
import eu.etaxonomy.cdm.model.common.CdmBase;
9 6

  
cdmlib-persistence/src/main/resources/eu/etaxonomy/cdm/persistence.xml
48 48
            <value>eu.etaxonomy.cdm.model.common.Extension</value>
49 49
            <value>eu.etaxonomy.cdm.model.common.ExtensionType</value>
50 50
            <value>eu.etaxonomy.cdm.model.common.Figure</value>
51
            <value>eu.etaxonomy.cdm.model.common.IDefTerm</value>
51
            <value>eu.etaxonomy.cdm.model.common.ILoadableTerm</value>
52 52
            <value>eu.etaxonomy.cdm.model.common.IdentifiableEntity</value>
53 53
            <value>eu.etaxonomy.cdm.model.common.IdentifyableMediaEntity</value>
54 54
            <value>eu.etaxonomy.cdm.model.common.IEvent</value>
cdmlib-services/src/test/resources/log4j.properties
21 21

  
22 22
	### *** CDM *** ###
23 23

  
24
log4j.logger.eu.etaxonomy.cdm = info 
24
log4j.logger.eu.etaxonomy.cdm = info
25 25
log4j.logger.eu.etaxonomy.cdm.database.init = debug
26
log4j.logger.eu.etaxonomy.cdm.model.common.init = debug
26 27

  
27 28

  
28 29
	### *** SPRING ************ ###

Also available in: Unified diff