Project

General

Profile

« Previous | Next » 

Revision 7f8eb81f

Added by Andreas Müller over 12 years ago

some bugfixes on DwcA Export

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaRecordBase.java
205 205
			String strToPrint = addSeparator ? config.getFieldsTerminatedBy() : "";
206 206
			if (StringUtils.isNotBlank(value)){
207 207
				value = value.replace(config.getLinesTerminatedBy(), "\\r");
208
				
209
				//replace all line brakes according to best practices: http://code.google.com/p/gbif-ecat/wiki/BestPractices
210
				value = value.replace("\r\n", "\\r");
211
				value = value.replace("\r", "\\r");
212
				value = value.replace("\n", "\\r");
213
				
208 214
				strToPrint += config.getFieldsEnclosedBy() + value + config.getFieldsEnclosedBy();
209 215
			}
210 216
			writer.print(strToPrint);
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaResourceRelationExport.java
112 112
						continue;
113 113
					}
114 114
					if (! this.recordExistsUuid(rel)){
115
						handleRelationship(record, subject, object, rel);
115
						handleRelationship(record, subject, object, rel, false);
116 116
						record.write(writer);
117 117
						this.addExistingRecordUuid(rel);
118 118
					}
......
130 130
				Set<NameRelationship> rels = name.getNameRelations();
131 131
				for (NameRelationship rel : rels){
132 132
					DwcaResourceRelationRecord record = new DwcaResourceRelationRecord(metaRecord, config);
133
					IdentifiableEntity<?> subject = rel.getFromName();
134
					IdentifiableEntity<?> object = rel.getToName();
133
					IdentifiableEntity<?> subject = CdmBase.deproxy(rel.getFromName(), TaxonNameBase.class); 
134
					IdentifiableEntity<?> object = CdmBase.deproxy(rel.getToName(), TaxonNameBase.class);
135
					boolean isInverse = false;
136
					if(subject == name){
137
						subject = taxon;
138
					}else if(object == name){
139
						object= subject;
140
						subject = taxon;
141
						isInverse = true;
142
					}else{
143
						String message = "Both, subject and object, are not part of the relationship for " + name.getTitleCache();
144
						logger.warn(message);
145
					}
135 146
					
136 147
					if (! this.recordExistsUuid(rel)){
137 148
						//????
138
						handleRelationship(record, subject, object, rel);
149
						handleRelationship(record, subject, object, rel, isInverse);
139 150
						record.write(writer);
140 151
						this.addExistingRecordUuid(rel);
141 152
					}
......
162 173
	}
163 174

  
164 175
	private void handleRelationship(DwcaResourceRelationRecord record, IdentifiableEntity<?> subject, IdentifiableEntity<?> object,
165
			RelationshipBase<?,?,?> rel) {
176
			RelationshipBase<?,?,?> rel, boolean isInverse) {
166 177
		RelationshipTermBase<?> type = rel.getType();
178
		
167 179
		record.setId(subject.getId());
168 180
		record.setUuid(subject.getUuid());
169 181
		
......
171 183
		record.setResourceRelationshipId(rel.getId());
172 184
		record.setResourceRelationshipId(rel.getUuid());
173 185
		//TODO id / uuid / names ??
174
		if (subject.isInstanceOf(TaxonBase.class)){
186
		if (object.isInstanceOf(TaxonBase.class)){
175 187
			record.setRelatedResourceId(object.getUuid());
176 188
		}
177 189
		//TODO transform to controlled voc
178
		record.setRelationshipOfResource(type.getLabel());
190
		String relTypeLabel;
191
		if (isInverse){
192
			relTypeLabel = type.getInverseLabel();
193
		}else{
194
			relTypeLabel = type.getLabel();
195
		}
196
		record.setRelationshipOfResource(relTypeLabel);
179 197
		record.setRelationshipAccordingTo(rel.getCitation()== null? null : rel.getCitation().getTitleCache());
180 198
		//TODO missing
181 199
		record.setRelatioshipEstablishedDate(null);
182 200
		record.setRelationshipRemarks(rel.getAnnotations());
183
		if (subject.isInstanceOf(TaxonNameBase.class)){
184
			record.setScientificName(subject.getTitleCache());
201
		if (object.isInstanceOf(TaxonNameBase.class)){
202
			record.setScientificName(object.getTitleCache());
185 203
		}
186 204
		
187 205
		

Also available in: Unified diff