1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.referenceris.in;
|
10
|
|
11
|
import static org.junit.Assert.assertNotNull;
|
12
|
|
13
|
import java.io.FileNotFoundException;
|
14
|
import java.io.IOException;
|
15
|
import java.net.URL;
|
16
|
import java.util.Collections;
|
17
|
import java.util.List;
|
18
|
|
19
|
import org.junit.Assert;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.Test;
|
22
|
import org.unitils.dbunit.annotation.DataSet;
|
23
|
import org.unitils.spring.annotation.SpringBeanByName;
|
24
|
import org.unitils.spring.annotation.SpringBeanByType;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
27
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
28
|
//import eu.etaxonomy.cdm.common.DOI;
|
29
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
30
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
31
|
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
|
32
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
33
|
import eu.etaxonomy.cdm.model.agent.Person;
|
34
|
import eu.etaxonomy.cdm.model.agent.Team;
|
35
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
36
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
37
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
38
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
39
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
40
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
41
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
42
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
43
|
|
44
|
/**
|
45
|
* @author a.mueller
|
46
|
*/
|
47
|
public class RisReferenceImportTest extends CdmTransactionalIntegrationTest {
|
48
|
|
49
|
@SpringBeanByName
|
50
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
51
|
|
52
|
@SpringBeanByType
|
53
|
private IReferenceService referenceService;
|
54
|
|
55
|
@SpringBeanByType
|
56
|
private IAgentService agentService;
|
57
|
|
58
|
@Before
|
59
|
public void setUp() {}
|
60
|
|
61
|
//***************************** TESTS *************************************//
|
62
|
|
63
|
@Test
|
64
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
65
|
//@Ignore
|
66
|
public void testShort() {
|
67
|
RisReferenceImportConfigurator configurator = getConfigurator("RisReferenceImportTest-input.ris");
|
68
|
ImportResult result = defaultImport.invoke(configurator);
|
69
|
String report = result.createReport().toString();
|
70
|
Assert.assertTrue(report.length() > 0);
|
71
|
// System.out.println(report);
|
72
|
|
73
|
Integer expected = 2;
|
74
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
75
|
|
76
|
List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
|
77
|
Assert.assertEquals("There should be 3 references, the article and the journal and the source reference",
|
78
|
3, list.size());
|
79
|
for (Reference ref : list){
|
80
|
if (ref.equals(configurator.getSourceReference())){
|
81
|
continue;
|
82
|
}
|
83
|
Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
|
84
|
if (ref.getType() == ReferenceType.Article){
|
85
|
//title
|
86
|
Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
|
87
|
ref.getTitle());
|
88
|
//author
|
89
|
TeamOrPersonBase<?> author = ref.getAuthorship();
|
90
|
Assert.assertNotNull(author);
|
91
|
Assert.assertTrue(author.isInstanceOf(Person.class));
|
92
|
Person person = CdmBase.deproxy(author, Person.class);
|
93
|
//this may change in future depending on the correct formatting strategy
|
94
|
Assert.assertEquals("Jongkind, C.C.H.", person.getTitleCache());
|
95
|
Assert.assertEquals("Jongkind", person.getFamilyName());
|
96
|
Assert.assertEquals("Carel C. H.", person.getGivenName());
|
97
|
//date
|
98
|
VerbatimTimePeriod date = ref.getDatePublished();
|
99
|
Assert.assertEquals(Integer.valueOf(2017), date.getStartYear());
|
100
|
//vol
|
101
|
Assert.assertEquals("47(1)", ref.getVolume());
|
102
|
Assert.assertEquals("43-47", ref.getPages());
|
103
|
|
104
|
//doi
|
105
|
//Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"), ref.getDoi());
|
106
|
|
107
|
//Abstract
|
108
|
Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.",
|
109
|
ref.getReferenceAbstract());
|
110
|
|
111
|
//TODO still missing Y1, Y2, M3, UR
|
112
|
|
113
|
}else if (ref.getType() == ReferenceType.Journal){
|
114
|
Assert.assertEquals("Willdenowia", ref.getTitle());
|
115
|
//or is this part of article?
|
116
|
Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
|
117
|
|
118
|
//ISSN
|
119
|
Assert.assertEquals("0511-9618" ,ref.getIssn());
|
120
|
|
121
|
}else{
|
122
|
Assert.fail("Only an article and a journal should exist");
|
123
|
}
|
124
|
}
|
125
|
}
|
126
|
|
127
|
@Test
|
128
|
public void testChapter() {
|
129
|
|
130
|
final RisReferenceImportConfigurator configurator = getConfigurator("Arias2012.ris");
|
131
|
|
132
|
ImportResult result = defaultImport.invoke(configurator);
|
133
|
String report = result.createReport().toString();
|
134
|
Assert.assertTrue(report.contains("Reference: 2"));
|
135
|
Assert.assertEquals(0, result.getErrors().size() + result.getExceptions().size() + result.getWarnings().size());
|
136
|
|
137
|
Integer expected = 2;
|
138
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
139
|
|
140
|
List<Reference> referenceList = referenceService.list(Reference.class, null, null, null, null);
|
141
|
Assert.assertEquals("There should be 3 references, the book-section, the book and the source reference",
|
142
|
3, referenceList.size());
|
143
|
|
144
|
//book section
|
145
|
Reference bookSection = referenceList.stream().filter(r->r.getType() == ReferenceType.BookSection).findFirst().get();
|
146
|
//... title
|
147
|
Assert.assertEquals("Cactaceae", bookSection.getTitle());
|
148
|
//... author
|
149
|
TeamOrPersonBase<?> author = bookSection.getAuthorship();
|
150
|
Assert.assertNotNull(author);
|
151
|
Team team = CdmBase.deproxy(author, Team.class);
|
152
|
Assert.assertEquals(4, team.getTeamMembers().size());
|
153
|
Person firstPerson = CdmBase.deproxy(team.getTeamMembers().get(0));
|
154
|
//this may change in future depending on the correct formatting strategy
|
155
|
Assert.assertEquals("Arias, S." , firstPerson.getTitleCache());
|
156
|
Assert.assertEquals("Arias" , firstPerson.getFamilyName());
|
157
|
Assert.assertNull(firstPerson.getGivenName());
|
158
|
Assert.assertEquals("S." , firstPerson.getInitials());
|
159
|
Person secondPerson = CdmBase.deproxy(team.getTeamMembers().get(1));
|
160
|
Assert.assertEquals("Gama-L\u00F3pez, S." , secondPerson.getTitleCache());
|
161
|
VerbatimTimePeriod date = bookSection.getDatePublished();
|
162
|
Assert.assertEquals(Integer.valueOf(2012), date.getStartYear());
|
163
|
//TODO correct?
|
164
|
Assert.assertEquals("1-235", bookSection.getPages());
|
165
|
|
166
|
//book
|
167
|
Reference book = referenceList.stream().filter(r->r.getType() == ReferenceType.Book).findFirst().get();
|
168
|
//... title
|
169
|
Assert.assertEquals("Flora del Valle de Tehuac\u00E1n-Cuicatl\u00E1n", book.getTitle());
|
170
|
Assert.assertEquals("Fasc\u00EDculo 95", book.getVolume());
|
171
|
Assert.assertEquals("M\u00E9xico D. F.", book.getPlacePublished());
|
172
|
Assert.assertEquals("Instituto de Biolog\u00EDa, Universidad Nacional Aut\u00F3noma de M\u00E9xico", book.getPublisher());
|
173
|
|
174
|
//source reference
|
175
|
Reference sourceRef = referenceList.stream().filter(r->r.equals(configurator.getSourceReference())).findFirst().get();
|
176
|
Assert.assertNotNull(sourceRef);
|
177
|
//TODO cont.
|
178
|
|
179
|
List<Person> personList = agentService.list(Person.class, null, null, null, null);
|
180
|
Assert.assertEquals("There should be 5 persons", 5, personList.size());
|
181
|
|
182
|
List<Team> teamList = agentService.list(Team.class, null, null, null, null);
|
183
|
Assert.assertEquals("There should be 1 team", 1, teamList.size());
|
184
|
|
185
|
|
186
|
//test deduplication by running it again
|
187
|
result = defaultImport.invoke(configurator);
|
188
|
report = result.createReport().toString();
|
189
|
Assert.assertTrue(report.contains("Reference: 0"));
|
190
|
Assert.assertEquals(0, result.getErrors().size() + result.getExceptions().size() + result.getWarnings().size());
|
191
|
referenceList = referenceService.list(Reference.class, null, null, null, null);
|
192
|
Assert.assertEquals("There should still be 3 references, the book-section, the book and the source reference",
|
193
|
3, referenceList.size());
|
194
|
|
195
|
personList = agentService.list(Person.class, null, null, null, null);
|
196
|
Assert.assertEquals("There should still be 5 persons", 5, personList.size());
|
197
|
|
198
|
teamList = agentService.list(Team.class, null, null, null, null);
|
199
|
Assert.assertEquals("There should still be 1 team", 1, teamList.size());
|
200
|
|
201
|
//test deduplication by running another chapter
|
202
|
RisReferenceImportConfigurator configurator2 = getConfigurator("Arias2012_2.ris");
|
203
|
result = defaultImport.invoke(configurator2);
|
204
|
report = result.createReport().toString();
|
205
|
// Assert.assertTrue(report.contains("Reference: 0"));
|
206
|
Assert.assertEquals(0, result.getErrors().size() + result.getExceptions().size() + result.getWarnings().size());
|
207
|
referenceList = referenceService.list(Reference.class, null, null, null, null);
|
208
|
Assert.assertEquals("There should be 5 references, 2 book-sections, the book and 2 source references",
|
209
|
5, referenceList.size());
|
210
|
|
211
|
personList = agentService.list(Person.class, null, null, null, null);
|
212
|
Assert.assertEquals("There should be 6 persons now", 6, personList.size());
|
213
|
|
214
|
teamList = agentService.list(Team.class, null, null, null, null);
|
215
|
Assert.assertEquals("There should be 2 teams now", 2, teamList.size());
|
216
|
|
217
|
}
|
218
|
|
219
|
private RisReferenceImportConfigurator getConfigurator(String fileName) {
|
220
|
String inputFile = "/eu/etaxonomy/cdm/io/reference/ris/in/" + fileName;
|
221
|
URL url = this.getClass().getResource(inputFile);
|
222
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
223
|
try {
|
224
|
RisReferenceImportConfigurator result = RisReferenceImportConfigurator.NewInstance(url, null);
|
225
|
result.setDeduplicationMaxCountForFullLoad(1);
|
226
|
return result;
|
227
|
} catch (IOException e) {
|
228
|
Assert.fail("IOException while creating configurator: " + e.getMessage());
|
229
|
return null;
|
230
|
}
|
231
|
}
|
232
|
|
233
|
@Test
|
234
|
public void testLongFile() {
|
235
|
|
236
|
RisReferenceImportConfigurator configurator = getConfigurator("Acantholimon.ris");
|
237
|
ImportResult result = defaultImport.invoke(configurator);
|
238
|
|
239
|
@SuppressWarnings("unused")
|
240
|
String report = result.createReport().toString();
|
241
|
// System.out.println(report);
|
242
|
|
243
|
// Integer expectedWithoutDeduplication = 118; //did not count yet
|
244
|
Integer expectedDeduplicated = 104; //did not count yet
|
245
|
Assert.assertEquals(expectedDeduplicated, result.getNewRecords(Reference.class));
|
246
|
// System.out.println("Person: "+ result.getNewRecords(Person.class));
|
247
|
// System.out.println("Team: "+ result.getNewRecords(Team.class));
|
248
|
|
249
|
List<Reference> refList = referenceService.list(Reference.class, null, null, null, null);
|
250
|
// Assert.assertEquals("There should be 119 references (still need to count them)", 119, refList.size());
|
251
|
Collections.sort(refList, (r1,r2) -> r1.getTitleCache().compareTo(r2.getTitleCache()));
|
252
|
printList(refList);
|
253
|
List<Person> personList = agentService.list(Person.class, null, null, null, null);
|
254
|
printList(personList);
|
255
|
Assert.assertEquals(99, personList.size());
|
256
|
List<Team> teamList = agentService.list(Team.class, null, null, null, null);
|
257
|
printList(teamList);
|
258
|
Assert.assertEquals(33, teamList.size());
|
259
|
List<Institution> institutionList = agentService.list(Institution.class, null, null, null, null);
|
260
|
printList(institutionList);
|
261
|
Assert.assertEquals(0, institutionList.size());
|
262
|
|
263
|
|
264
|
Reference ref58 = refList.stream().filter(r->hasId(r, "58", false)).findFirst().get();
|
265
|
Assert.assertNotNull("", ref58);
|
266
|
Assert.assertEquals((Integer)2003, ref58.getDatePublished().getStartYear());
|
267
|
|
268
|
Reference ref53 = refList.stream().filter(r->hasId(r, "53", false)).findFirst().get();
|
269
|
Assert.assertNotNull("", ref53);
|
270
|
Assert.assertEquals(ReferenceType.BookSection, ref53.getType());
|
271
|
Assert.assertNotNull("", ref53.getInReference());
|
272
|
Assert.assertEquals("Tehran", ref53.getInReference().getPlacePublished());
|
273
|
|
274
|
|
275
|
// for (Reference ref : list){
|
276
|
// Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
|
277
|
// if (ref.getType() == ReferenceType.Article){
|
278
|
// //title
|
279
|
// Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
|
280
|
// ref.getTitle());
|
281
|
// //author
|
282
|
// TeamOrPersonBase<?> author = ref.getAuthorship();
|
283
|
// Assert.assertNotNull(author);
|
284
|
// Assert.assertTrue(author.isInstanceOf(Person.class));
|
285
|
// Person person = CdmBase.deproxy(author, Person.class);
|
286
|
// //this may change in future depending on the correct formatting strategy
|
287
|
// Assert.assertEquals("Carel C. H. Jongkind" ,person.getTitleCache());
|
288
|
// Assert.assertEquals("Jongkind" ,person.getFamilyName());
|
289
|
// Assert.assertEquals("Carel C. H." ,person.getGivenName());
|
290
|
// //date
|
291
|
// TimePeriod date = ref.getDatePublished();
|
292
|
// Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
|
293
|
// //vol
|
294
|
// Assert.assertEquals("47(1)" ,ref.getVolume());
|
295
|
// Assert.assertEquals("43-47" ,ref.getPages());
|
296
|
//
|
297
|
// //doi
|
298
|
// Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
|
299
|
//
|
300
|
// //Abstract
|
301
|
// Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.",
|
302
|
// ref.getReferenceAbstract());
|
303
|
//
|
304
|
// //TODO still missing Y1, Y2, M3, UR
|
305
|
//
|
306
|
// }else if (ref.getType() == ReferenceType.Journal){
|
307
|
// Assert.assertEquals("Willdenowia", ref.getTitle());
|
308
|
// //or is this part of article?
|
309
|
// Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
|
310
|
//
|
311
|
// //ISSN
|
312
|
// Assert.assertEquals("0511-9618" ,ref.getIssn());
|
313
|
//
|
314
|
// }else{
|
315
|
// Assert.fail("Only an article and a journal should exist");
|
316
|
// }
|
317
|
// }
|
318
|
}
|
319
|
|
320
|
private void printList(List<? extends IdentifiableEntity<?>> list) {
|
321
|
if (!logger.isDebugEnabled()){
|
322
|
return;
|
323
|
}
|
324
|
System.out.println(list.size());
|
325
|
Collections.sort(list, (p1,p2) -> p1.getTitleCache().compareTo(p2.getTitleCache()));
|
326
|
list.stream().forEach(r->System.out.println(r.getTitleCache()));
|
327
|
}
|
328
|
|
329
|
private boolean hasId(Reference ref, String idStr, boolean getInRef) {
|
330
|
if (ref.getSources().size() != 1){
|
331
|
return false;
|
332
|
}else{
|
333
|
String idInSource = ref.getSources().iterator().next().getIdInSource();
|
334
|
return idStr.equals(idInSource) &&
|
335
|
(getInRef && ref.getInReference()== null
|
336
|
|| !getInRef && ref.getInReference()!= null );
|
337
|
}
|
338
|
}
|
339
|
|
340
|
@Override
|
341
|
public void createTestDataSet() throws FileNotFoundException {}
|
342
|
}
|