Revision d457f5b7
Added by Andreas Müller over 2 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/reference/ris/in/RisReferenceImport.java | ||
---|---|---|
31 | 31 |
import eu.etaxonomy.cdm.model.common.Annotation; |
32 | 32 |
import eu.etaxonomy.cdm.model.common.AnnotationType; |
33 | 33 |
import eu.etaxonomy.cdm.model.common.Language; |
34 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
35 | 34 |
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod; |
36 | 35 |
import eu.etaxonomy.cdm.model.reference.Reference; |
37 | 36 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
38 | 37 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
38 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; |
|
39 | 39 |
|
40 | 40 |
/** |
41 | 41 |
* @author a.mueller |
... | ... | |
157 | 157 |
RisValue da = getSingleValue(state, record, RisReferenceTag.DA); |
158 | 158 |
Integer year = makeYear(state, py); |
159 | 159 |
VerbatimTimePeriod date = makeDate(state, da); |
160 |
assertDateYear(state, year, date, py); |
|
160 |
date = assertDateYear(state, year, date, py);
|
|
161 | 161 |
ref.setDatePublished(date); |
162 | 162 |
//TODO y1 not yet handled |
163 | 163 |
|
... | ... | |
217 | 217 |
higherRef.setPublisher(pb.value); |
218 | 218 |
} |
219 | 219 |
|
220 |
//CY - Place published |
|
221 |
RisValue cy = getSingleValue(state, record, RisReferenceTag.CY); |
|
222 |
if (cy != null){ |
|
223 |
higherRef.setPlacePublished(cy.value); |
|
224 |
} |
|
225 |
|
|
220 | 226 |
//Abstract |
221 | 227 |
RisValue ab = getSingleValue(state, record, RisReferenceTag.AB); |
222 | 228 |
RisValue n2 = getSingleValue(state, record, RisReferenceTag.N2); |
... | ... | |
241 | 247 |
String recLoc = recordLocation(state, record); |
242 | 248 |
ref.addImportSource(idStr, null, state.getConfig().getSourceReference(), recLoc); |
243 | 249 |
if (inRef != null){ |
244 |
ref.addImportSource(idStr, null, state.getConfig().getSourceReference(), recLoc); |
|
245 |
|
|
250 |
inRef.addImportSource(idStr, null, state.getConfig().getSourceReference(), recLoc); |
|
246 | 251 |
} |
247 | 252 |
|
248 | 253 |
//remove |
... | ... | |
277 | 282 |
return result; |
278 | 283 |
} |
279 | 284 |
|
280 |
private void assertDateYear(RisReferenceImportState state, Integer year, TimePeriod date, RisValue py) { |
|
281 |
if (year != null && date != null && !year.equals(date.getStartYear())){ |
|
282 |
String message = "Year 'PY' and date 'DA' are not consistent. PY is neglected."; |
|
283 |
state.getResult().addWarning(message, null, py.location); |
|
285 |
private VerbatimTimePeriod assertDateYear(RisReferenceImportState state, Integer year, VerbatimTimePeriod date, RisValue py) { |
|
286 |
if (year == null && date == null){ |
|
287 |
return null; |
|
288 |
}else if (year == null){ |
|
289 |
return date; |
|
290 |
}else if (date == null){ |
|
291 |
return TimePeriodParser.parseStringVerbatim(String.valueOf(year)); |
|
292 |
}else{ |
|
293 |
if (!year.equals(date.getStartYear())){ |
|
294 |
if (date.getStartYear() == null){ |
|
295 |
date.setStartYear(year); |
|
296 |
}else if (isNotBlank(date.getFreeText())){ |
|
297 |
date.setStartYear(year); //does this happen at all? |
|
298 |
String message = "Year 'PY' and date 'DA' are not consistent. PY is neglected."; |
|
299 |
state.getResult().addWarning(message, null, py.location); |
|
300 |
return date; |
|
301 |
}else{ |
|
302 |
String message = "Year 'PY' and date 'DA' are not consistent. DA is used for freetext and PY is used for (start) year."; |
|
303 |
state.getResult().addWarning(message, null, py.location); |
|
304 |
return date; |
|
305 |
} |
|
306 |
} |
|
307 |
return date; |
|
284 | 308 |
} |
285 | 309 |
} |
286 | 310 |
|
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/referenceris/in/RisReferenceImportTest.java | ||
---|---|---|
150 | 150 |
Integer expected = 118; //did not count yet |
151 | 151 |
Assert.assertEquals(expected, result.getNewRecords(Reference.class)); |
152 | 152 |
|
153 |
// List<Reference> list = referenceService.list(Reference.class, null, null, null, null); |
|
154 |
// Assert.assertEquals("There should be 2 references, the article and the journal", 2, list.size()); |
|
155 |
// for (Reference ref : list){ |
|
153 |
List<Reference> list = referenceService.list(Reference.class, null, null, null, null); |
|
154 |
// Assert.assertEquals("There should be 119 references (still need to count them)", 119, list.size()); |
|
155 |
//TODO deduplication |
|
156 |
|
|
157 |
Reference ref58 = list.stream().filter(r->hasId(r, "58", false)).findFirst().get(); |
|
158 |
Assert.assertNotNull("", ref58); |
|
159 |
Assert.assertEquals((Integer)2003, ref58.getDatePublished().getStartYear()); |
|
160 |
|
|
161 |
Reference ref53 = list.stream().filter(r->hasId(r, "53", false)).findFirst().get(); |
|
162 |
Assert.assertNotNull("", ref53); |
|
163 |
Assert.assertEquals(ReferenceType.BookSection, ref53.getType()); |
|
164 |
Assert.assertNotNull("", ref53.getInReference()); |
|
165 |
Assert.assertEquals("Tehran", ref53.getInReference().getPlacePublished()); |
|
166 |
|
|
167 |
|
|
168 |
// for (Reference ref : list){ |
|
156 | 169 |
// Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal); |
157 | 170 |
// if (ref.getType() == ReferenceType.Article){ |
158 | 171 |
// //title |
... | ... | |
198 | 211 |
|
199 | 212 |
} |
200 | 213 |
|
214 |
private boolean hasId(Reference ref, String idStr, boolean getInRef) { |
|
215 |
if (ref.getSources().size() != 1){ |
|
216 |
return false; |
|
217 |
}else{ |
|
218 |
String idInSource = ref.getSources().iterator().next().getIdInSource(); |
|
219 |
return idStr.equals(idInSource) && |
|
220 |
(getInRef && ref.getInReference()== null |
|
221 |
|| !getInRef && ref.getInReference()!= null ); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
201 | 225 |
@Override |
202 | 226 |
public void createTestDataSet() throws FileNotFoundException {} |
203 | 227 |
} |
Also available in: Unified diff
fix #9786 implement CY and fix PY for RIS import (and fix Source handling for in-references)