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.berlinModel.in;
|
10
|
|
11
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_ARTICLE;
|
12
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_BOOK;
|
13
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_CONFERENCE_PROCEEDINGS;
|
14
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_DATABASE;
|
15
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_INFORMAL;
|
16
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_JOURNAL;
|
17
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_JOURNAL_VOLUME;
|
18
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_PART_OF_OTHER_TITLE;
|
19
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_PRINT_SERIES;
|
20
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_UNKNOWN;
|
21
|
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.REF_WEBSITE;
|
22
|
import static eu.etaxonomy.cdm.io.common.ImportHelper.NO_OVERWRITE;
|
23
|
import static eu.etaxonomy.cdm.io.common.ImportHelper.OBLIGATORY;
|
24
|
import static eu.etaxonomy.cdm.io.common.ImportHelper.OVERWRITE;
|
25
|
|
26
|
import java.net.URISyntaxException;
|
27
|
import java.sql.ResultSet;
|
28
|
import java.sql.SQLException;
|
29
|
import java.util.ArrayList;
|
30
|
import java.util.Arrays;
|
31
|
import java.util.HashMap;
|
32
|
import java.util.HashSet;
|
33
|
import java.util.List;
|
34
|
import java.util.Map;
|
35
|
import java.util.Set;
|
36
|
import java.util.UUID;
|
37
|
import java.util.regex.Matcher;
|
38
|
import java.util.regex.Pattern;
|
39
|
|
40
|
import org.apache.log4j.Logger;
|
41
|
import org.springframework.stereotype.Component;
|
42
|
|
43
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
44
|
import eu.etaxonomy.cdm.common.DOI;
|
45
|
import eu.etaxonomy.cdm.common.URI;
|
46
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
47
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelReferenceImportValidator;
|
48
|
import eu.etaxonomy.cdm.io.common.ICdmImport;
|
49
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
50
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
51
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
52
|
import eu.etaxonomy.cdm.io.common.Source;
|
53
|
import eu.etaxonomy.cdm.io.common.mapping.CdmAttributeMapperBase;
|
54
|
import eu.etaxonomy.cdm.io.common.mapping.CdmIoMapping;
|
55
|
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
|
56
|
import eu.etaxonomy.cdm.io.common.mapping.DbImportExtensionMapper;
|
57
|
import eu.etaxonomy.cdm.io.common.mapping.DbImportMarkerMapper;
|
58
|
import eu.etaxonomy.cdm.io.common.mapping.DbSingleAttributeImportMapperBase;
|
59
|
import eu.etaxonomy.cdm.io.common.mapping.berlinModel.CdmOneToManyMapper;
|
60
|
import eu.etaxonomy.cdm.io.common.mapping.berlinModel.CdmStringMapper;
|
61
|
import eu.etaxonomy.cdm.io.common.mapping.berlinModel.CdmUriMapper;
|
62
|
import eu.etaxonomy.cdm.model.agent.Person;
|
63
|
import eu.etaxonomy.cdm.model.agent.Team;
|
64
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
65
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
66
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
67
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
68
|
import eu.etaxonomy.cdm.model.common.Identifier;
|
69
|
import eu.etaxonomy.cdm.model.common.Marker;
|
70
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
71
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
72
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
73
|
import eu.etaxonomy.cdm.model.reference.IPrintSeries;
|
74
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
75
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
76
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
77
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
78
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
79
|
import eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy;
|
80
|
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
|
81
|
|
82
|
/**
|
83
|
* @author a.mueller
|
84
|
* @since 20.03.2008
|
85
|
*/
|
86
|
@Component
|
87
|
public class BerlinModelReferenceImport extends BerlinModelImportBase {
|
88
|
private static final long serialVersionUID = -3667566958769967591L;
|
89
|
|
90
|
private static final Logger logger = Logger.getLogger(BerlinModelReferenceImport.class);
|
91
|
|
92
|
public static final String REFERENCE_NAMESPACE = "Reference";
|
93
|
private static final String REF_AUTHOR_NAMESPACE = "Reference.refAuthorString";
|
94
|
|
95
|
public static final UUID REF_DEPOSITED_AT_UUID = UUID.fromString("23ca88c7-ce73-41b2-8ca3-2cb22f013beb");
|
96
|
public static final UUID REF_SOURCE_UUID = UUID.fromString("d6432582-2216-4b08-b0db-76f6c1013141");
|
97
|
public static final UUID DATE_STRING_UUID = UUID.fromString("e4130eae-606e-4b0c-be4f-e93dc161be7d");
|
98
|
public static final UUID IS_PAPER_UUID = UUID.fromString("8a326129-d0d0-4f9d-bbdf-8d86b037c65e");
|
99
|
|
100
|
private final int modCount = 1000;
|
101
|
private static final String pluralString = "references";
|
102
|
private static final String dbTableName = "reference";
|
103
|
|
104
|
public BerlinModelReferenceImport(){
|
105
|
super(dbTableName, pluralString);
|
106
|
}
|
107
|
|
108
|
protected void initializeMappers(BerlinModelImportState state){
|
109
|
for (CdmAttributeMapperBase mapper: classMappers){
|
110
|
if (mapper instanceof DbSingleAttributeImportMapperBase){
|
111
|
@SuppressWarnings("unchecked")
|
112
|
DbSingleAttributeImportMapperBase<BerlinModelImportState,Reference> singleMapper =
|
113
|
(DbSingleAttributeImportMapperBase<BerlinModelImportState,Reference>)mapper;
|
114
|
singleMapper.initialize(state, Reference.class);
|
115
|
}
|
116
|
}
|
117
|
return;
|
118
|
}
|
119
|
|
120
|
private Set<Integer> commonNameRefSet = null;
|
121
|
private void initializeCommonNameRefMap(BerlinModelImportState state) throws SQLException{
|
122
|
if (state.getConfig().isEuroMed()){
|
123
|
commonNameRefSet = new HashSet<>();
|
124
|
String queryStr = "SELECT DISTINCT RefFk "
|
125
|
+ " FROM emCommonName ";
|
126
|
ResultSet rs = state.getConfig().getSource().getResultSet(queryStr);
|
127
|
while (rs.next()){
|
128
|
commonNameRefSet.add(rs.getInt("RefFk"));
|
129
|
}
|
130
|
}
|
131
|
}
|
132
|
|
133
|
protected static CdmAttributeMapperBase[] classMappers = new CdmAttributeMapperBase[]{
|
134
|
new CdmStringMapper("edition", "edition"),
|
135
|
new CdmStringMapper("volume", "volume"),
|
136
|
new CdmStringMapper("publisher", "publisher"),
|
137
|
new CdmStringMapper("publicationTown", "placePublished"),
|
138
|
new CdmStringMapper("isbn", "isbn"),
|
139
|
new CdmStringMapper("isbn", "isbn"),
|
140
|
new CdmStringMapper("pageString", "pages"),
|
141
|
new CdmStringMapper("series", "seriesPart"),
|
142
|
new CdmStringMapper("issn", "issn"),
|
143
|
new CdmUriMapper("url", "uri"),
|
144
|
DbImportExtensionMapper.NewInstance("NomStandard", ExtensionType.NOMENCLATURAL_STANDARD()),
|
145
|
DbImportExtensionMapper.NewInstance("DateString", DATE_STRING_UUID, "Date String", "Date String", "dates"),
|
146
|
DbImportExtensionMapper.NewInstance("RefDepositedAt", REF_DEPOSITED_AT_UUID, "Ref. deposited at", "Reference is deposited at", "at"),
|
147
|
DbImportExtensionMapper.NewInstance("RefSource", REF_SOURCE_UUID, "RefSource", "Reference Source", "source"),
|
148
|
DbImportMarkerMapper.NewInstance("isPaper", IS_PAPER_UUID, "is paper", "is paper", "paper", false)
|
149
|
//not yet supported by model
|
150
|
,new CdmStringMapper("refAuthorString", "refAuthorString"),
|
151
|
};
|
152
|
|
153
|
protected static String[] operationalAttributes = new String[]{
|
154
|
"refId", "refCache", "nomRefCache", "preliminaryFlag", "inRefFk", "title", "nomTitleAbbrev",
|
155
|
"refAuthorString", "nomAuthorTeamFk",
|
156
|
"refCategoryFk", "thesisFlag", "informalRefCategory", "idInSource"
|
157
|
};
|
158
|
|
159
|
protected static String[] createdAndNotesAttributes = new String[]{
|
160
|
"created_When", "updated_When", "created_Who", "updated_Who", "notes"
|
161
|
};
|
162
|
|
163
|
protected static String[] unclearMappers = new String[]{
|
164
|
/*"isPaper",*/ "exportDate",
|
165
|
};
|
166
|
|
167
|
//TODO isPaper
|
168
|
//
|
169
|
|
170
|
//type to count the references nomReferences that have been created and saved
|
171
|
private class RefCounter{
|
172
|
RefCounter() {refCount = 0;}
|
173
|
int refCount;
|
174
|
int dedupCount;
|
175
|
|
176
|
@Override
|
177
|
public String toString(){return String.valueOf(refCount) + "/" + String.valueOf(dedupCount) ;}
|
178
|
}
|
179
|
|
180
|
@Override
|
181
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
182
|
return null; //not needed
|
183
|
}
|
184
|
|
185
|
@Override
|
186
|
protected void doInvoke(BerlinModelImportState state){
|
187
|
logger.info("start make " + getPluralString() + " ...");
|
188
|
|
189
|
boolean success = true;
|
190
|
initializeMappers(state);
|
191
|
try {
|
192
|
initializeCommonNameRefMap(state);
|
193
|
} catch (SQLException e1) {
|
194
|
e1.printStackTrace();
|
195
|
logger.error("Error in initializeCommonNameRefMap in BerlinModelReferenceimport");
|
196
|
}
|
197
|
BerlinModelImportConfigurator config = state.getConfig();
|
198
|
Source source = config.getSource();
|
199
|
|
200
|
String strSelectId = " SELECT Reference.RefId as refId ";
|
201
|
String strSelectFull =
|
202
|
" SELECT Reference.* ,InReference.RefCategoryFk as InRefCategoryFk, RefSource.RefSource " ;
|
203
|
String strFrom =
|
204
|
" FROM %s " +
|
205
|
" LEFT OUTER JOIN Reference as InReference ON InReference.refId = Reference.inRefFk " +
|
206
|
" LEFT OUTER JOIN RefSource ON Reference.RefSourceFk = RefSource.RefSourceId " +
|
207
|
" WHERE (1=1) ";
|
208
|
String strOrderBy = " ORDER BY InReference.inRefFk, Reference.inRefFk "; //to make in-references available in first run
|
209
|
String strWherePartitioned = " AND (Reference.refId IN ("+ ID_LIST_TOKEN + ") ) ";
|
210
|
|
211
|
String referenceTable = CdmUtils.Nz(state.getConfig().getReferenceIdTable());
|
212
|
referenceTable = referenceTable.isEmpty() ? " Reference" : referenceTable + " as Reference ";
|
213
|
String strIdFrom = String.format(strFrom, referenceTable );
|
214
|
|
215
|
String referenceFilter = CdmUtils.Nz(state.getConfig().getReferenceIdTable());
|
216
|
if (! referenceFilter.isEmpty()){
|
217
|
referenceFilter = " AND " + referenceFilter + " ";
|
218
|
}
|
219
|
referenceFilter = ""; //don't use it for now, in E+M the tabelle is directly used
|
220
|
|
221
|
String strIdQueryFirstPath = strSelectId + strIdFrom + strOrderBy ;
|
222
|
String strIdQuerySecondPath = strSelectId + strIdFrom + " AND (Reference.InRefFk is NOT NULL) ";
|
223
|
|
224
|
// if (config.getDoReferences() == CONCEPT_REFERENCES){
|
225
|
// strIdQueryNoInRef += " AND ( Reference.refId IN ( SELECT ptRefFk FROM PTaxon) ) " + referenceFilter;
|
226
|
// }
|
227
|
|
228
|
String strRecordQuery = strSelectFull + String.format(strFrom, " Reference ") + strWherePartitioned + strOrderBy;
|
229
|
|
230
|
int recordsPerTransaction = config.getRecordsPerTransaction();
|
231
|
try{
|
232
|
//firstPath
|
233
|
ResultSetPartitioner<BerlinModelImportState> partitioner =
|
234
|
ResultSetPartitioner.NewInstance(source, strIdQueryFirstPath, strRecordQuery, recordsPerTransaction);
|
235
|
while (partitioner.nextPartition()){
|
236
|
partitioner.doPartition(this, state);
|
237
|
}
|
238
|
logger.info("end make references without in-references ... " + getSuccessString(success));
|
239
|
state.setReferenceSecondPath(true);
|
240
|
|
241
|
//secondPath
|
242
|
// partitioner = ResultSetPartitioner.NewInstance(source, strIdQuerySecondPath, strRecordQuery, recordsPerTransaction);
|
243
|
// while (partitioner.nextPartition()){
|
244
|
// //currently not used as inRef assignment fully works through sorting of idQuery now, at least in E+M
|
245
|
// partitioner.doPartition(this, state);
|
246
|
// }
|
247
|
// logger.info("end make references with no 1 in-reference ... " + getSuccessString(success));
|
248
|
state.setReferenceSecondPath(false);
|
249
|
logger.warn("Parsed book volumes: " + parsedBookVolumes);
|
250
|
} catch (SQLException e) {
|
251
|
logger.error("SQLException:" + e);
|
252
|
state.setUnsuccessfull();
|
253
|
return;
|
254
|
}
|
255
|
logger.info("end make " + getPluralString() + " ... " + getSuccessString(success));
|
256
|
if (! success){
|
257
|
state.setUnsuccessfull();
|
258
|
}
|
259
|
return;
|
260
|
}
|
261
|
|
262
|
@Override
|
263
|
public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
264
|
state.getDeduplicationHelper().restartSession();
|
265
|
|
266
|
if (state.isReferenceSecondPath()){
|
267
|
return doPartitionSecondPath(partitioner, state);
|
268
|
}
|
269
|
boolean success = true;
|
270
|
|
271
|
Map<Integer, Reference> refToSave = new HashMap<>();
|
272
|
|
273
|
BerlinModelImportConfigurator config = state.getConfig();
|
274
|
|
275
|
try {
|
276
|
|
277
|
int i = 0;
|
278
|
RefCounter refCounter = new RefCounter();
|
279
|
ResultSet rs = partitioner.getResultSet();
|
280
|
|
281
|
//for each resultset
|
282
|
while (rs.next()){
|
283
|
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("References handled: " + (i-1) + " in round -" );}
|
284
|
|
285
|
success &= makeSingleReferenceRecord(rs, state, partitioner, refToSave, refCounter);
|
286
|
} // end resultSet
|
287
|
|
288
|
//for the concept reference a fixed uuid may be needed -> change uuid
|
289
|
Integer sourceSecId = (Integer)config.getSourceSecId();
|
290
|
Reference sec = refToSave.get(sourceSecId);
|
291
|
|
292
|
if (sec != null){
|
293
|
sec.setUuid(config.getSecUuid());
|
294
|
logger.info("SecUuid changed to: " + config.getSecUuid());
|
295
|
}
|
296
|
|
297
|
//save and store in map
|
298
|
logger.warn("Save references (" + refCounter.toString() + ")"); //set preliminary to warn for printing dedup count
|
299
|
|
300
|
getReferenceService().saveOrUpdate(refToSave.values());
|
301
|
|
302
|
// logger.info("end makeReferences ..." + getSuccessString(success));;
|
303
|
return success;
|
304
|
} catch (SQLException e) {
|
305
|
logger.error("SQLException:" + e);
|
306
|
return false;
|
307
|
}
|
308
|
}
|
309
|
|
310
|
|
311
|
|
312
|
/**
|
313
|
* Adds the inReference to the according references.
|
314
|
* @param partitioner
|
315
|
* @param state
|
316
|
* @return
|
317
|
*/
|
318
|
private boolean doPartitionSecondPath(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
319
|
boolean success = true;
|
320
|
|
321
|
Map<Integer, Reference> refToSave = new HashMap<>();
|
322
|
|
323
|
@SuppressWarnings("unchecked")
|
324
|
Map<String, Reference> relatedReferencesMap = partitioner.getObjectMap(REFERENCE_NAMESPACE);
|
325
|
|
326
|
try {
|
327
|
int i = 0;
|
328
|
RefCounter refCounter = new RefCounter();
|
329
|
|
330
|
ResultSet rs = partitioner.getResultSet();
|
331
|
//for each resultset
|
332
|
while (rs.next()){
|
333
|
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("References handled: " + (i-1) + " in round -" );}
|
334
|
|
335
|
Integer refId = rs.getInt("refId");
|
336
|
Integer inRefFk = nullSafeInt(rs, "inRefFk");
|
337
|
|
338
|
if (inRefFk != null){
|
339
|
|
340
|
Reference thisRef = relatedReferencesMap.get(String.valueOf(refId));
|
341
|
|
342
|
Reference inRef = relatedReferencesMap.get(String.valueOf(inRefFk));
|
343
|
|
344
|
if (thisRef != null){
|
345
|
if (inRef == null){
|
346
|
logger.warn("No InRef found for nomRef: " + thisRef.getTitleCache() + "; RefId: " + refId + "; inRefFK: " + inRefFk);
|
347
|
}
|
348
|
thisRef.setInReference(inRef);
|
349
|
refToSave.put(refId, thisRef);
|
350
|
if(!thisRef.isProtectedTitleCache()){
|
351
|
thisRef.setTitleCache(null);
|
352
|
thisRef.getTitleCache();
|
353
|
}
|
354
|
}else{
|
355
|
logger.warn("Reference which has an inReference not found in DB. RefId: " + refId);
|
356
|
}
|
357
|
if(inRefFk.equals(0)){
|
358
|
logger.warn("InRefFk is 0 for refId "+ refId);
|
359
|
}
|
360
|
}
|
361
|
|
362
|
} // end resultSet
|
363
|
|
364
|
//save and store in map
|
365
|
logger.info("Save in references (" + refCounter.toString() + ")");
|
366
|
getReferenceService().saveOrUpdate(refToSave.values());
|
367
|
|
368
|
// }//end resultSetList
|
369
|
|
370
|
// logger.info("end makeReferences ..." + getSuccessString(success));;
|
371
|
return success;
|
372
|
} catch (SQLException e) {
|
373
|
logger.error("SQLException:" + e);
|
374
|
return false;
|
375
|
}
|
376
|
}
|
377
|
|
378
|
|
379
|
@Override
|
380
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
381
|
|
382
|
String nameSpace;
|
383
|
Set<String> idSet;
|
384
|
|
385
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
386
|
|
387
|
try{
|
388
|
Set<String> teamIdSet = new HashSet<>();
|
389
|
Set<String> referenceIdSet = new HashSet<>();
|
390
|
Set<String> teamStringSet = new HashSet<>();
|
391
|
|
392
|
while (rs.next()){
|
393
|
handleForeignKey(rs, teamIdSet, "NomAuthorTeamFk");
|
394
|
handleForeignKey(rs, referenceIdSet, "InRefFk");
|
395
|
handleForeignKey(rs, teamStringSet, "refAuthorString");
|
396
|
//TODO only needed in second path but state not available here to check if state is second path
|
397
|
handleForeignKey(rs, referenceIdSet, "refId");
|
398
|
}
|
399
|
|
400
|
Set<String> teamStringSet2 = new HashSet<>();
|
401
|
for (String teamString : teamStringSet){
|
402
|
teamStringSet2.add(teamString.replace("'", "´"));
|
403
|
}
|
404
|
|
405
|
//team map
|
406
|
nameSpace = BerlinModelAuthorTeamImport.NAMESPACE;
|
407
|
idSet = teamIdSet;
|
408
|
@SuppressWarnings("rawtypes")
|
409
|
Map<String, TeamOrPersonBase> teamMap = getCommonService().getSourcedObjectsByIdInSourceC(TeamOrPersonBase.class, idSet, nameSpace);
|
410
|
result.put(nameSpace, teamMap);
|
411
|
|
412
|
//refAuthor map
|
413
|
nameSpace = REF_AUTHOR_NAMESPACE;
|
414
|
idSet = teamStringSet2;
|
415
|
@SuppressWarnings("unchecked")
|
416
|
Map<String, TeamOrPersonBase> refAuthorMap = getCommonService().getSourcedObjectsByIdInSourceC(TeamOrPersonBase.class, idSet, nameSpace);
|
417
|
result.put(nameSpace, refAuthorMap);
|
418
|
|
419
|
//reference map
|
420
|
nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
|
421
|
idSet = referenceIdSet;
|
422
|
Map<String, Reference> referenceMap = getCommonService().getSourcedObjectsByIdInSourceC(Reference.class, idSet, nameSpace);
|
423
|
result.put(nameSpace, referenceMap);
|
424
|
|
425
|
} catch (SQLException e) {
|
426
|
throw new RuntimeException(e);
|
427
|
}
|
428
|
return result;
|
429
|
}
|
430
|
|
431
|
|
432
|
/**
|
433
|
* Handles a single reference record
|
434
|
* @param rs
|
435
|
* @param state
|
436
|
* @param biblioRefToSave
|
437
|
* @param nomRefToSave
|
438
|
* @param relatedBiblioReferences
|
439
|
* @param relatedNomReferences
|
440
|
* @param refCounter
|
441
|
* @return
|
442
|
*/
|
443
|
private boolean makeSingleReferenceRecord(
|
444
|
ResultSet rs,
|
445
|
BerlinModelImportState state,
|
446
|
ResultSetPartitioner<BerlinModelImportState> partitioner,
|
447
|
Map<Integer, Reference> refToSave,
|
448
|
RefCounter refCounter){
|
449
|
|
450
|
boolean success = true;
|
451
|
|
452
|
Integer refId = null;
|
453
|
try {
|
454
|
Map<String, Object> valueMap = getValueMap(rs);
|
455
|
|
456
|
Integer categoryFk = (Integer)valueMap.get("refCategoryFk".toLowerCase());
|
457
|
refId = (Integer)valueMap.get("refId".toLowerCase());
|
458
|
Boolean thesisFlag = (Boolean)valueMap.get("thesisFlag".toLowerCase());
|
459
|
|
460
|
|
461
|
Reference reference;
|
462
|
logger.debug("RefCategoryFk: " + categoryFk);
|
463
|
|
464
|
if (thesisFlag){
|
465
|
reference = makeThesis(valueMap);
|
466
|
}else if (categoryFk == REF_JOURNAL){
|
467
|
reference = makeJournal(valueMap);
|
468
|
}else if(categoryFk == REF_BOOK){
|
469
|
reference = makeBook(valueMap);
|
470
|
}else if(categoryFk == REF_DATABASE){
|
471
|
reference = makeDatabase(valueMap);
|
472
|
}else if(categoryFk == REF_INFORMAL){
|
473
|
reference = makeInformal(valueMap);
|
474
|
}else if(categoryFk == REF_WEBSITE){
|
475
|
reference = makeWebSite(valueMap);
|
476
|
}else if(categoryFk == REF_UNKNOWN){
|
477
|
reference = makeUnknown(valueMap);
|
478
|
}else if(categoryFk == REF_PRINT_SERIES){
|
479
|
reference = makePrintSeries(valueMap);
|
480
|
}else if(categoryFk == REF_CONFERENCE_PROCEEDINGS){
|
481
|
reference = makeProceedings(valueMap);
|
482
|
}else if(categoryFk == REF_ARTICLE){
|
483
|
reference = makeArticle(valueMap);
|
484
|
}else if(categoryFk == REF_JOURNAL_VOLUME){
|
485
|
reference = makeJournalVolume(valueMap);
|
486
|
}else if(categoryFk == REF_PART_OF_OTHER_TITLE){
|
487
|
reference = makePartOfOtherTitle(valueMap);
|
488
|
}else{
|
489
|
logger.warn("Unknown categoryFk (" + categoryFk + "). Create 'Generic instead'");
|
490
|
reference = ReferenceFactory.newGeneric();
|
491
|
success = false;
|
492
|
}
|
493
|
|
494
|
//refYear
|
495
|
String refYear = (String)valueMap.get("refYear".toLowerCase());
|
496
|
reference.setDatePublished(ImportHelper.getDatePublished(refYear));
|
497
|
|
498
|
handleEdition(reference);
|
499
|
|
500
|
//created, updated, notes
|
501
|
doCreatedUpdatedNotes(state, reference, rs);
|
502
|
|
503
|
//idInSource (import from older source to berlin model)
|
504
|
//TODO do we want this being imported? Maybe as alternatvie identifier?
|
505
|
String idInSource = (String)valueMap.get("IdInSource".toLowerCase());
|
506
|
if (isNotBlank(idInSource)){
|
507
|
if(!state.getConfig().isDoSourceNumber()){
|
508
|
IdentifiableSource source = IdentifiableSource.NewDataImportInstance(idInSource);
|
509
|
source.setIdNamespace("import to Berlin Model");
|
510
|
reference.addSource(source);
|
511
|
}else{
|
512
|
makeSourceNumbers(state, idInSource, reference, refId);
|
513
|
}
|
514
|
}
|
515
|
String uuid = null;
|
516
|
if (resultSetHasColumn(rs,"UUID")){
|
517
|
uuid = rs.getString("UUID");
|
518
|
if (uuid != null){
|
519
|
reference.setUuid(UUID.fromString(uuid));
|
520
|
}
|
521
|
}
|
522
|
|
523
|
//nom&BiblioReference - must be last because a clone is created
|
524
|
success &= makeNomAndBiblioReference(rs, state, partitioner, refId, reference, refCounter, refToSave);
|
525
|
|
526
|
|
527
|
} catch (Exception e) {
|
528
|
logger.warn("Reference with BM refId '" + CdmUtils.Nz(refId) + "' threw Exception and could not be saved");
|
529
|
e.printStackTrace();
|
530
|
success = false;
|
531
|
}
|
532
|
return success;
|
533
|
}
|
534
|
|
535
|
|
536
|
/**
|
537
|
* @param state
|
538
|
* @param idInSource
|
539
|
* @param reference
|
540
|
* @param refId
|
541
|
*/
|
542
|
private void makeSourceNumbers(BerlinModelImportState state, String idInSource, Reference reference,
|
543
|
Integer refId) {
|
544
|
String[] splits = idInSource.split("\\|");
|
545
|
for (String split : splits){
|
546
|
split = split.trim();
|
547
|
UUID uuid = BerlinModelTransformer.uuidEMReferenceSourceNumber;
|
548
|
TermVocabulary<DefinedTerm> voc = null; //user defined voc
|
549
|
DefinedTerm type = getIdentiferType(state, uuid, "E+M Reference Source Number", "Euro+Med Reference Source Number", "E+M Source Number", voc);
|
550
|
Identifier.NewInstance(reference, split, type);
|
551
|
}
|
552
|
}
|
553
|
|
554
|
/**
|
555
|
* @param reference
|
556
|
*/
|
557
|
private void handleEdition(Reference reference) {
|
558
|
if (reference.getEdition()!= null && reference.getEdition().startsWith("ed. ")){
|
559
|
reference.setEdition(reference.getEdition().substring(4));
|
560
|
}
|
561
|
|
562
|
}
|
563
|
|
564
|
/**
|
565
|
* Creates and saves a nom. reference and a biblio. reference after checking necessity
|
566
|
* @param rs
|
567
|
* @param refId
|
568
|
* @param ref
|
569
|
* @param refCounter
|
570
|
* @param biblioRefToSave
|
571
|
* @param nomRefToSave
|
572
|
* @param teamMap
|
573
|
* @param stores
|
574
|
* @return
|
575
|
* @throws SQLException
|
576
|
*/
|
577
|
private boolean makeNomAndBiblioReference(
|
578
|
ResultSet rs,
|
579
|
BerlinModelImportState state,
|
580
|
@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner,
|
581
|
int refId,
|
582
|
Reference ref,
|
583
|
RefCounter refCounter,
|
584
|
Map<Integer, Reference> refToSave
|
585
|
) throws SQLException{
|
586
|
|
587
|
@SuppressWarnings("unchecked")
|
588
|
Map<String, Team> teamMap = partitioner.getObjectMap(BerlinModelAuthorTeamImport.NAMESPACE);
|
589
|
|
590
|
String refCache = trim(rs.getString("refCache"));
|
591
|
String nomRefCache = trim(rs.getString("nomRefCache"));
|
592
|
String title = trim(rs.getString("title"));
|
593
|
String nomTitleAbbrev = trim(rs.getString("nomTitleAbbrev"));
|
594
|
boolean isPreliminary = rs.getBoolean("PreliminaryFlag");
|
595
|
String refAuthorString = trim(rs.getString("refAuthorString"));
|
596
|
Integer nomAuthorTeamFk = nullSafeInt(rs, "NomAuthorTeamFk");
|
597
|
Integer inRefFk = nullSafeInt(rs, "inRefFk");
|
598
|
|
599
|
|
600
|
TeamOrPersonBase<?> nomAuthor = null;
|
601
|
if (nomAuthorTeamFk != null){
|
602
|
String strNomAuthorTeamFk = String.valueOf(nomAuthorTeamFk);
|
603
|
nomAuthor = teamMap.get(strNomAuthorTeamFk);
|
604
|
if (nomAuthor == null){
|
605
|
logger.warn("NomAuthor ("+strNomAuthorTeamFk+") not found in teamMap (but it should exist) for " + refId);
|
606
|
}
|
607
|
}
|
608
|
|
609
|
Reference sourceReference = state.getTransactionalSourceReference();
|
610
|
|
611
|
//preliminary
|
612
|
if (isPreliminary){
|
613
|
ref.setAbbrevTitleCache(nomRefCache, true);
|
614
|
ref.setTitleCache(refCache, true);
|
615
|
}
|
616
|
|
617
|
//title/abbrevTitle
|
618
|
if (isNotBlank(nomTitleAbbrev)){
|
619
|
ref.setAbbrevTitle(nomTitleAbbrev);
|
620
|
}
|
621
|
if (isNotBlank(title)){
|
622
|
ref.setTitle(title);
|
623
|
}
|
624
|
|
625
|
//author
|
626
|
TeamOrPersonBase<?> author = getAuthorship(state, refAuthorString, nomAuthor, refId);
|
627
|
ref.setAuthorship(author);
|
628
|
|
629
|
if (ref.getType().equals(ReferenceType.Book)){
|
630
|
extraktBookVolume(ref);
|
631
|
}
|
632
|
|
633
|
//inRef
|
634
|
Reference inRef = null;
|
635
|
if (inRefFk != null){
|
636
|
@SuppressWarnings({"unchecked" })
|
637
|
Map<String, Reference> relatedReferences = partitioner.getObjectMap(REFERENCE_NAMESPACE);
|
638
|
inRef = relatedReferences.get(String.valueOf(inRefFk));
|
639
|
if (inRef == null){
|
640
|
inRef = refToSave.get(inRefFk);
|
641
|
}
|
642
|
if (inRef == null){
|
643
|
logger.warn("InRef not (yet) found. RefId: " + refId + "; InRef: "+ inRefFk);
|
644
|
}else{
|
645
|
ref.setInReference(inRef);
|
646
|
}
|
647
|
}
|
648
|
|
649
|
Reference result = deduplicateReference(state, ref);
|
650
|
if(ref != result){
|
651
|
//dedup not possible at this point because inRef exists but is not yet defined
|
652
|
if (inRefFk != null && inRef == null){
|
653
|
result = ref;
|
654
|
logger.warn("Ref has deduplication candidate but inRef is still missing. " + inRef);
|
655
|
}else{
|
656
|
logger.debug("Reference was deduplicated. RefId: " + refId);
|
657
|
//FIXME also check annotations etc. for deduplication
|
658
|
refCounter.dedupCount++;
|
659
|
}
|
660
|
}else{
|
661
|
refCounter.refCount++;
|
662
|
}
|
663
|
|
664
|
//save
|
665
|
if (! refToSave.containsKey(refId)){
|
666
|
refToSave.put(refId, result);
|
667
|
}else{
|
668
|
//should not happen
|
669
|
logger.warn("Duplicate refId in Berlin Model database. Second reference was not imported !!");
|
670
|
}
|
671
|
|
672
|
|
673
|
//refId
|
674
|
ImportHelper.setOriginalSource(result, sourceReference, refId, REFERENCE_NAMESPACE);
|
675
|
|
676
|
if (commonNameRefSet != null && commonNameRefSet.contains(refId)){
|
677
|
result.addMarker(Marker.NewInstance(MarkerType.COMMON_NAME_REFERENCE(), true));
|
678
|
}
|
679
|
|
680
|
return true;
|
681
|
}
|
682
|
|
683
|
/**
|
684
|
* @param string
|
685
|
* @return
|
686
|
*/
|
687
|
private String trim(String string) {
|
688
|
if (string == null){
|
689
|
return null;
|
690
|
}else{
|
691
|
return string.trim();
|
692
|
}
|
693
|
}
|
694
|
|
695
|
/**
|
696
|
* Copies the created and updated information from the nomReference to the cloned bibliographic reference
|
697
|
* @param referenceBase
|
698
|
* @param nomReference
|
699
|
*/
|
700
|
private void copyCreatedUpdated(Reference biblioReference, Reference nomReference) {
|
701
|
biblioReference.setCreatedBy(nomReference.getCreatedBy());
|
702
|
biblioReference.setCreated(nomReference.getCreated());
|
703
|
biblioReference.setUpdatedBy(nomReference.getUpdatedBy());
|
704
|
biblioReference.setUpdated(nomReference.getUpdated());
|
705
|
|
706
|
}
|
707
|
|
708
|
private Reference makeArticle (Map<String, Object> valueMap){
|
709
|
|
710
|
IArticle article = ReferenceFactory.newArticle();
|
711
|
Object inRefFk = valueMap.get("inRefFk".toLowerCase());
|
712
|
Integer inRefCategoryFk = (Integer)valueMap.get("inRefCategoryFk".toLowerCase());
|
713
|
Integer refId = (Integer)valueMap.get("refId".toLowerCase());
|
714
|
|
715
|
if (inRefFk != null){
|
716
|
if (inRefCategoryFk != REF_JOURNAL){
|
717
|
logger.warn("Wrong inrefCategory for Article (refID = " + refId +"). Type must be 'Journal' but was not (RefCategoryFk=" + inRefCategoryFk + "))." +
|
718
|
" InReference was added anyway! ");
|
719
|
}
|
720
|
}else{
|
721
|
logger.warn ("Article has no inreference: " + refId);
|
722
|
}
|
723
|
makeStandardMapper(valueMap, (Reference)article); //url, pages, series, volume
|
724
|
String url = (String)valueMap.get("url");
|
725
|
if (url != null && url.contains("dx.doi.org")){
|
726
|
article.setDoi(DOI.fromString(url));
|
727
|
article.setUri(null);
|
728
|
}
|
729
|
return (Reference)article;
|
730
|
}
|
731
|
|
732
|
private Reference makePartOfOtherTitle (Map<String, Object> valueMap){
|
733
|
|
734
|
Reference result;
|
735
|
Object inRefFk = valueMap.get("inRefFk".toLowerCase());
|
736
|
Integer inRefCategoryFk = (Integer)valueMap.get("inRefCategoryFk".toLowerCase());
|
737
|
Integer refId = (Integer)valueMap.get("refId".toLowerCase());
|
738
|
|
739
|
if (inRefCategoryFk == null){
|
740
|
//null -> error
|
741
|
logger.warn("Part-Of-Other-Title has no inRefCategoryFk! RefId = " + refId + ". ReferenceType set to Generic.");
|
742
|
result = makeUnknown(valueMap);
|
743
|
}else if (inRefFk == null){
|
744
|
//TODO is this correct ??
|
745
|
logger.warn("Part-Of-Other-Title has no in reference: " + refId);
|
746
|
result = makeUnknown(valueMap);
|
747
|
}else if (inRefCategoryFk == REF_BOOK){
|
748
|
//BookSection
|
749
|
IBookSection bookSection = ReferenceFactory.newBookSection();
|
750
|
result = (Reference)bookSection;
|
751
|
}else if (inRefCategoryFk == REF_ARTICLE){
|
752
|
//Article
|
753
|
logger.info("Reference (refId = " + refId + ") of type 'part_of_other_title' is part of 'article'." +
|
754
|
" We use the section reference type for such in references now.") ;
|
755
|
result = ReferenceFactory.newSection();
|
756
|
}else if (inRefCategoryFk == REF_JOURNAL){
|
757
|
//TODO
|
758
|
logger.warn("Reference (refId = " + refId + ") of type 'part_of_other_title' has inReference of type 'journal'." +
|
759
|
" This is not allowed! Generic reference created instead") ;
|
760
|
result = ReferenceFactory.newGeneric();
|
761
|
result.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true));
|
762
|
}else if (inRefCategoryFk == REF_PART_OF_OTHER_TITLE){
|
763
|
logger.info("Reference (refId = " + refId + ") of type 'part_of_other_title' has inReference 'part of other title'." +
|
764
|
" This is allowed, but may be true only for specific cases (e.g. parts of book chapters). You may want to check if this is correct") ;
|
765
|
result = ReferenceFactory.newSection();
|
766
|
}else{
|
767
|
logger.warn("InReference type (catFk = " + inRefCategoryFk + ") of part-of-reference not recognized for refId " + refId + "." +
|
768
|
" Create 'Generic' reference instead");
|
769
|
result = ReferenceFactory.newGeneric();
|
770
|
}
|
771
|
makeStandardMapper(valueMap, result); //url, pages
|
772
|
return result;
|
773
|
}
|
774
|
|
775
|
|
776
|
/**
|
777
|
* @param inRefFkInt
|
778
|
* @param biblioRefToSave
|
779
|
* @param nomRefToSave
|
780
|
* @param relatedBiblioReferences
|
781
|
* @param relatedNomReferences
|
782
|
* @return
|
783
|
*/
|
784
|
private boolean existsInMapOrToSave(Integer inRefFkInt, Map<Integer, Reference> refToSave, Map<String, Reference> relatedReferences) {
|
785
|
boolean result = false;
|
786
|
if (inRefFkInt == null){
|
787
|
return false;
|
788
|
}
|
789
|
result |= refToSave.containsKey(inRefFkInt);
|
790
|
result |= relatedReferences.containsKey(String.valueOf(inRefFkInt));
|
791
|
return result;
|
792
|
}
|
793
|
|
794
|
private Reference makeWebSite(Map<String, Object> valueMap){
|
795
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Website'");}
|
796
|
Reference webPage = ReferenceFactory.newWebPage();
|
797
|
makeStandardMapper(valueMap, webPage); //placePublished, publisher
|
798
|
return webPage;
|
799
|
}
|
800
|
|
801
|
private Reference makeUnknown(Map<String, Object> valueMap){
|
802
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Unknown'");}
|
803
|
Reference generic = ReferenceFactory.newGeneric();
|
804
|
// generic.setSeries(series);
|
805
|
makeStandardMapper(valueMap, generic); //pages, placePublished, publisher, series, volume
|
806
|
return generic;
|
807
|
}
|
808
|
|
809
|
private Reference makeInformal(Map<String, Object> valueMap){
|
810
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Informal'");}
|
811
|
Reference generic = ReferenceFactory.newGeneric();
|
812
|
// informal.setSeries(series);
|
813
|
makeStandardMapper(valueMap, generic);//editor, pages, placePublished, publisher, series, volume
|
814
|
String informal = (String)valueMap.get("InformalRefCategory".toLowerCase());
|
815
|
if (isNotBlank(informal) ){
|
816
|
generic.addExtension(informal, ExtensionType.INFORMAL_CATEGORY());
|
817
|
}
|
818
|
return generic;
|
819
|
}
|
820
|
|
821
|
private Reference makeDatabase(Map<String, Object> valueMap){
|
822
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Database'");}
|
823
|
Reference database = ReferenceFactory.newDatabase();
|
824
|
makeStandardMapper(valueMap, database); //?
|
825
|
return database;
|
826
|
}
|
827
|
|
828
|
private Reference makeJournal(Map<String, Object> valueMap){
|
829
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Journal'");}
|
830
|
Reference journal = ReferenceFactory.newJournal();
|
831
|
|
832
|
Set<String> omitAttributes = new HashSet<>();
|
833
|
String series = "series";
|
834
|
// omitAttributes.add(series);
|
835
|
|
836
|
makeStandardMapper(valueMap, journal, omitAttributes); //issn,placePublished,publisher
|
837
|
// if (valueMap.get(series) != null){
|
838
|
// logger.warn("Series not yet implemented for journal!");
|
839
|
// }
|
840
|
return journal;
|
841
|
}
|
842
|
|
843
|
private Reference makeBook(
|
844
|
Map<String, Object> valueMap){
|
845
|
|
846
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Book'");}
|
847
|
Reference book = ReferenceFactory.newBook();
|
848
|
// Integer refId = (Integer)valueMap.get("refId".toLowerCase());
|
849
|
|
850
|
//Set bookAttributes = new String[]{"edition", "isbn", "pages","publicationTown","publisher","volume"};
|
851
|
|
852
|
Set<String> omitAttributes = new HashSet<>();
|
853
|
String attrSeries = "series";
|
854
|
// omitAttributes.add(attrSeries);
|
855
|
|
856
|
makeStandardMapper(valueMap, book, omitAttributes);
|
857
|
|
858
|
//Series (as String)
|
859
|
IPrintSeries printSeries = null;
|
860
|
if (valueMap.get(attrSeries) != null){
|
861
|
String series = (String)valueMap.get("title".toLowerCase());
|
862
|
if (series == null){
|
863
|
String nomTitle = (String)valueMap.get("nomTitleAbbrev".toLowerCase());
|
864
|
series = nomTitle;
|
865
|
}
|
866
|
printSeries = ReferenceFactory.newPrintSeries(series);
|
867
|
logger.info("Implementation of printSeries is preliminary");
|
868
|
}
|
869
|
//Series (as Reference)
|
870
|
if (book.getInSeries() != null && printSeries != null){
|
871
|
logger.warn("Book has series string and inSeries reference. Can not take both. Series string neglected");
|
872
|
}else{
|
873
|
book.setInSeries(printSeries);
|
874
|
}
|
875
|
book.setEditor(null);
|
876
|
|
877
|
return book;
|
878
|
|
879
|
}
|
880
|
|
881
|
|
882
|
int parsedBookVolumes = 0;
|
883
|
private void extraktBookVolume(Reference book) {
|
884
|
if (isExtractBookVolumeCandidate(book)){
|
885
|
String patternStr = "(.{2,})\\s(\\d{1,2})";
|
886
|
int groupIndex = 2;
|
887
|
Pattern pattern = Pattern.compile(patternStr);
|
888
|
|
889
|
String abbrevCache = book.getAbbrevTitleCache();
|
890
|
String titleCache = book.getTitleCache();
|
891
|
String vol = null;
|
892
|
String volFull = null;
|
893
|
String abbrev = book.getAbbrevTitle();
|
894
|
if (isNotBlank(abbrev)){
|
895
|
Matcher matcher = pattern.matcher(abbrev);
|
896
|
if (matcher.matches()){
|
897
|
vol = matcher.group(groupIndex);
|
898
|
abbrev = matcher.group(1);
|
899
|
}
|
900
|
}
|
901
|
|
902
|
String full = book.getTitle();
|
903
|
if (isNotBlank(full)){
|
904
|
Matcher matcher = pattern.matcher(full);
|
905
|
if (matcher.matches()){
|
906
|
volFull = matcher.group(groupIndex);
|
907
|
full = matcher.group(1);
|
908
|
}
|
909
|
}
|
910
|
if (vol != null && volFull != null){
|
911
|
if (!vol.equals(volFull)){
|
912
|
return;
|
913
|
}
|
914
|
}else if (vol == null && volFull == null){
|
915
|
return;
|
916
|
}else if (vol == null){
|
917
|
if (isNotBlank(abbrev)){
|
918
|
return;
|
919
|
}else{
|
920
|
vol = volFull;
|
921
|
}
|
922
|
}else if (volFull == null){
|
923
|
if (isNotBlank(full)){
|
924
|
return;
|
925
|
}
|
926
|
}else{
|
927
|
logger.warn("Should not happen");
|
928
|
}
|
929
|
book.setVolume(vol);
|
930
|
book.setAbbrevTitle(abbrev);
|
931
|
book.setTitle(full);
|
932
|
if (!book.getAbbrevTitleCache().equals(abbrevCache)){
|
933
|
logger.warn("Abbrev title cache for parsed book volume does not match: " + book.getAbbrevTitleCache() + " <-> "+abbrevCache);
|
934
|
}else if (!book.getTitleCache().equals(titleCache)){
|
935
|
logger.warn("Title cache for parsed book volume does not match: " + book.getTitleCache() + " <-> "+titleCache);
|
936
|
}else{
|
937
|
// System.out.println(titleCache);
|
938
|
// System.out.println(abbrevCache);
|
939
|
parsedBookVolumes++;
|
940
|
}
|
941
|
}else{
|
942
|
return;
|
943
|
}
|
944
|
}
|
945
|
|
946
|
/**
|
947
|
* @param book
|
948
|
* @return
|
949
|
*/
|
950
|
private boolean isExtractBookVolumeCandidate(Reference book) {
|
951
|
if (isNotBlank(book.getVolume()) || isNotBlank(book.getEdition()) || isNotBlank(book.getSeriesPart())){
|
952
|
return false;
|
953
|
}
|
954
|
if (!checkExtractBookVolumeTitle(book.getAbbrevTitle())){
|
955
|
return false;
|
956
|
}
|
957
|
if (!checkExtractBookVolumeTitle(book.getTitle())){
|
958
|
return false;
|
959
|
}
|
960
|
return true;
|
961
|
}
|
962
|
|
963
|
/**
|
964
|
* @param abbrevTitle
|
965
|
* @return
|
966
|
*/
|
967
|
private boolean checkExtractBookVolumeTitle(String title) {
|
968
|
if (title == null){
|
969
|
return true;
|
970
|
}
|
971
|
if (title.contains(",") || title.contains("ed.") || title.contains("Ed.")|| title.contains("Suppl")
|
972
|
|| title.contains("Ser.")|| title.contains("ser.")) {
|
973
|
return false;
|
974
|
}
|
975
|
return true;
|
976
|
}
|
977
|
|
978
|
/**
|
979
|
* Returns the requested object if it exists in one of both maps. Prefers the refToSaveMap in ambigious cases.
|
980
|
* @param inRefFkInt
|
981
|
* @param nomRefToSave
|
982
|
* @param relatedNomReferences
|
983
|
* @return
|
984
|
*/
|
985
|
private Reference getReferenceFromMaps(
|
986
|
int inRefFkInt,
|
987
|
Map<Integer, Reference> refToSaveMap,
|
988
|
Map<String, Reference> relatedRefMap) {
|
989
|
Reference result = null;
|
990
|
result = refToSaveMap.get(inRefFkInt);
|
991
|
if (result == null){
|
992
|
result = relatedRefMap.get(String.valueOf(inRefFkInt));
|
993
|
}
|
994
|
return result;
|
995
|
}
|
996
|
|
997
|
private Reference makePrintSeries(Map<String, Object> valueMap){
|
998
|
if (logger.isDebugEnabled()){logger.debug("RefType 'PrintSeries'");}
|
999
|
Reference printSeries = ReferenceFactory.newPrintSeries();
|
1000
|
makeStandardMapper(valueMap, printSeries, null);
|
1001
|
return printSeries;
|
1002
|
}
|
1003
|
|
1004
|
private Reference makeProceedings(Map<String, Object> valueMap){
|
1005
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Proceedings'");}
|
1006
|
Reference proceedings = ReferenceFactory.newProceedings();
|
1007
|
makeStandardMapper(valueMap, proceedings, null);
|
1008
|
return proceedings;
|
1009
|
}
|
1010
|
|
1011
|
private Reference makeThesis(Map<String, Object> valueMap){
|
1012
|
if (logger.isDebugEnabled()){logger.debug("RefType 'Thesis'");}
|
1013
|
Reference thesis = ReferenceFactory.newThesis();
|
1014
|
makeStandardMapper(valueMap, thesis, null);
|
1015
|
return thesis;
|
1016
|
}
|
1017
|
|
1018
|
|
1019
|
private Reference makeJournalVolume(Map<String, Object> valueMap){
|
1020
|
if (logger.isDebugEnabled()){logger.debug("RefType 'JournalVolume'");}
|
1021
|
//Proceedings proceedings = Proceedings.NewInstance();
|
1022
|
Reference journalVolume = ReferenceFactory.newGeneric();
|
1023
|
makeStandardMapper(valueMap, journalVolume, null);
|
1024
|
logger.warn("Journal volumes not yet implemented. Generic created instead but with errors");
|
1025
|
return journalVolume;
|
1026
|
}
|
1027
|
|
1028
|
private boolean makeStandardMapper(Map<String, Object> valueMap, Reference ref){
|
1029
|
return makeStandardMapper(valueMap, ref, null);
|
1030
|
}
|
1031
|
|
1032
|
|
1033
|
private boolean makeStandardMapper(Map<String, Object> valueMap, CdmBase cdmBase, Set<String> omitAttributes){
|
1034
|
boolean result = true;
|
1035
|
for (CdmAttributeMapperBase mapper : classMappers){
|
1036
|
if (mapper instanceof CdmSingleAttributeMapperBase){
|
1037
|
result &= makeStandardSingleMapper(valueMap, cdmBase, (CdmSingleAttributeMapperBase)mapper, omitAttributes);
|
1038
|
}else if (mapper instanceof CdmOneToManyMapper){
|
1039
|
result &= makeMultipleValueAddMapper(valueMap, cdmBase, (CdmOneToManyMapper)mapper, omitAttributes);
|
1040
|
}else{
|
1041
|
logger.error("Unknown mapper type");
|
1042
|
result = false;
|
1043
|
}
|
1044
|
}
|
1045
|
return result;
|
1046
|
}
|
1047
|
|
1048
|
private boolean makeStandardSingleMapper(Map<String, Object> valueMap, CdmBase cdmBase, CdmSingleAttributeMapperBase mapper, Set<String> omitAttributes){
|
1049
|
boolean result = true;
|
1050
|
if (omitAttributes == null){
|
1051
|
omitAttributes = new HashSet<>();
|
1052
|
}
|
1053
|
if (mapper instanceof DbImportExtensionMapper){
|
1054
|
result &= ((DbImportExtensionMapper)mapper).invoke(valueMap, cdmBase);
|
1055
|
}else if (mapper instanceof DbImportMarkerMapper){
|
1056
|
result &= ((DbImportMarkerMapper)mapper).invoke(valueMap, cdmBase);
|
1057
|
}else{
|
1058
|
String sourceAttribute = mapper.getSourceAttributeList().get(0).toLowerCase();
|
1059
|
Object value = valueMap.get(sourceAttribute);
|
1060
|
if (mapper instanceof CdmUriMapper && value != null){
|
1061
|
try {
|
1062
|
value = new URI (value.toString());
|
1063
|
} catch (URISyntaxException e) {
|
1064
|
logger.error("URI syntax exception: " + value.toString());
|
1065
|
value = null;
|
1066
|
}
|
1067
|
}
|
1068
|
if (value != null){
|
1069
|
String destinationAttribute = mapper.getDestinationAttribute();
|
1070
|
if (! omitAttributes.contains(destinationAttribute)){
|
1071
|
result &= ImportHelper.addValue(value, cdmBase, destinationAttribute, mapper.getTypeClass(), OVERWRITE, OBLIGATORY);
|
1072
|
}
|
1073
|
}
|
1074
|
}
|
1075
|
return result;
|
1076
|
}
|
1077
|
|
1078
|
|
1079
|
private boolean makeMultipleValueAddMapper(Map<String, Object> valueMap, CdmBase cdmBase, CdmOneToManyMapper<CdmBase, CdmBase, CdmSingleAttributeMapperBase> mapper, Set<String> omitAttributes){
|
1080
|
if (omitAttributes == null){
|
1081
|
omitAttributes = new HashSet<>();
|
1082
|
}
|
1083
|
boolean result = true;
|
1084
|
String destinationAttribute = mapper.getSingleAttributeName();
|
1085
|
List<Object> sourceValues = new ArrayList<>();
|
1086
|
List<Class> classes = new ArrayList<>();
|
1087
|
for (CdmSingleAttributeMapperBase singleMapper : mapper.getSingleMappers()){
|
1088
|
String sourceAttribute = singleMapper.getSourceAttribute();
|
1089
|
Object value = valueMap.get(sourceAttribute);
|
1090
|
sourceValues.add(value);
|
1091
|
Class<?> clazz = singleMapper.getTypeClass();
|
1092
|
classes.add(clazz);
|
1093
|
}
|
1094
|
|
1095
|
result &= ImportHelper.addMultipleValues(sourceValues, cdmBase, destinationAttribute, classes, NO_OVERWRITE, OBLIGATORY);
|
1096
|
return result;
|
1097
|
}
|
1098
|
|
1099
|
|
1100
|
private TeamOrPersonBase<?> getAuthorship(BerlinModelImportState state, String refAuthorString,
|
1101
|
TeamOrPersonBase<?> nomAuthor, Integer refId){
|
1102
|
|
1103
|
TeamOrPersonBase<?> result;
|
1104
|
if (nomAuthor != null){
|
1105
|
result = nomAuthor;
|
1106
|
if (isNotBlank(refAuthorString) && !nomAuthor.getTitleCache().equals(refAuthorString)){
|
1107
|
boolean isSimilar = handleSimilarAuthors(state, refAuthorString, nomAuthor, refId);
|
1108
|
if (! isSimilar){
|
1109
|
String message = "refAuthorString differs from nomAuthor.titleCache: " + refAuthorString
|
1110
|
+ " <-> " + nomAuthor.getTitleCache() + "; RefId: " + refId;
|
1111
|
logger.warn(message);
|
1112
|
}
|
1113
|
}
|
1114
|
} else if (isNotBlank(refAuthorString)){//only RefAuthorString exists
|
1115
|
refAuthorString = refAuthorString.trim();
|
1116
|
//TODO match with existing Persons/Teams
|
1117
|
TeamOrPersonBase<?> author = state.getRelatedObject(REF_AUTHOR_NAMESPACE, refAuthorString, TeamOrPersonBase.class);
|
1118
|
if (author == null){
|
1119
|
if (!BerlinModelAuthorTeamImport.hasTeamSeparator(refAuthorString)){
|
1120
|
author = makePerson(refAuthorString, false, refId);
|
1121
|
}else{
|
1122
|
author = makeTeam(state, refAuthorString, refId);
|
1123
|
}
|
1124
|
state.addRelatedObject(REF_AUTHOR_NAMESPACE, refAuthorString, author);
|
1125
|
result = deduplicatePersonOrTeam(state, author);
|
1126
|
|
1127
|
if (result != author){
|
1128
|
logger.debug("RefAuthorString author deduplicated " + author);
|
1129
|
}else{
|
1130
|
if (!importSourceExists(author, refAuthorString, REF_AUTHOR_NAMESPACE, state.getTransactionalSourceReference() )){
|
1131
|
author.addImportSource(refAuthorString, REF_AUTHOR_NAMESPACE, state.getTransactionalSourceReference(), null);
|
1132
|
}
|
1133
|
}
|
1134
|
}else{
|
1135
|
logger.debug("RefAuthor loaded from map");
|
1136
|
}
|
1137
|
result = author;
|
1138
|
}else{
|
1139
|
result = null;
|
1140
|
}
|
1141
|
|
1142
|
return result;
|
1143
|
}
|
1144
|
|
1145
|
|
1146
|
/**
|
1147
|
* @param state
|
1148
|
* @param refAuthorString
|
1149
|
* @param refId
|
1150
|
* @return
|
1151
|
*/
|
1152
|
private TeamOrPersonBase<?> makeTeam(BerlinModelImportState state, String refAuthorString, Integer refId) {
|
1153
|
Team team = Team.NewInstance();
|
1154
|
boolean hasDedupMember = false;
|
1155
|
if (containsEdOrColon(refAuthorString)){
|
1156
|
team.setTitleCache(refAuthorString, true);
|
1157
|
}else{
|
1158
|
String[] refAuthorTeams = BerlinModelAuthorTeamImport.splitTeam(refAuthorString);
|
1159
|
boolean lastWasInitials = false;
|
1160
|
for (int i = 0; i< refAuthorTeams.length ;i++){
|
1161
|
if (lastWasInitials){
|
1162
|
lastWasInitials = false;
|
1163
|
continue;
|
1164
|
}
|
1165
|
String fullTeam = refAuthorTeams[i].trim();
|
1166
|
String initials = null;
|
1167
|
if (refAuthorTeams.length > i+1){
|
1168
|
String nextSplit = refAuthorTeams[i+1].trim();
|
1169
|
if (isInitial(nextSplit)){
|
1170
|
lastWasInitials = true;
|
1171
|
initials = nextSplit;
|
1172
|
}
|
1173
|
}
|
1174
|
Person member = makePerson(fullTeam, isNotBlank(initials), refId);
|
1175
|
|
1176
|
if (initials != null){
|
1177
|
if (member.getInitials() != null){
|
1178
|
logger.warn("Initials already set: " + refId);
|
1179
|
}else if (!member.isProtectedTitleCache()){
|
1180
|
member.setInitials(initials);
|
1181
|
}else {
|
1182
|
member.setTitleCache(member.getTitleCache() + ", " + initials, true);
|
1183
|
}
|
1184
|
}
|
1185
|
|
1186
|
if (i == refAuthorTeams.length -1 && BerlinModelAuthorTeamImport.isEtAl(member)){
|
1187
|
team.setHasMoreMembers(true);
|
1188
|
}else{
|
1189
|
Person dedupMember = deduplicatePersonOrTeam(state, member);
|
1190
|
if (dedupMember != member){
|
1191
|
hasDedupMember = true;
|
1192
|
}else{
|
1193
|
if (!importSourceExists(member, refAuthorString, REF_AUTHOR_NAMESPACE, state.getTransactionalSourceReference())){
|
1194
|
member.addImportSource(refAuthorString, REF_AUTHOR_NAMESPACE, state.getTransactionalSourceReference(), null);
|
1195
|
}
|
1196
|
}
|
1197
|
|
1198
|
team.addTeamMember(dedupMember);
|
1199
|
}
|
1200
|
}
|
1201
|
}
|
1202
|
|
1203
|
TeamOrPersonBase<?> result = team;
|
1204
|
if (team.getTeamMembers().size() == 1 && !team.isHasMoreMembers()){
|
1205
|
Person person = team.getTeamMembers().get(0);
|
1206
|
checkPerson(person, refAuthorString, hasDedupMember, refId);
|
1207
|
result = person;
|
1208
|
}else{
|
1209
|
checkTeam(team, refAuthorString, refId);
|
1210
|
result = team;
|
1211
|
}
|
1212
|
|
1213
|
return result;
|
1214
|
}
|
1215
|
|
1216
|
private static void checkTeam(Team team, String refAuthorString, Integer refId) {
|
1217
|
TeamDefaultCacheStrategy formatter = (TeamDefaultCacheStrategy) team.cacheStrategy();
|
1218
|
|
1219
|
if (formatter.getTitleCache(team).equals(refAuthorString)){
|
1220
|
team.setProtectedTitleCache(false);
|
1221
|
}else if(formatter.getTitleCache(team).replace(" & ", ", ").equals(refAuthorString.replace(" & ", ", ").replace(" ,", ","))){
|
1222
|
//also accept teams with ', ' as final member separator as not protected
|
1223
|
team.setProtectedTitleCache(false);
|
1224
|
}else if(formatter.getFullTitle(team).replace(" & ", ", ").equals(refAuthorString.replace(" & ", ", "))){
|
1225
|
//.. or teams with initials first
|
1226
|
team.setProtectedTitleCache(false);
|
1227
|
}else if (containsEdOrColon(refAuthorString)){
|
1228
|
//nothing to do, it is expected to be protected
|
1229
|
|
1230
|
}else{
|
1231
|
team.setTitleCache(refAuthorString, true);
|
1232
|
logger.warn("Creation of titleCache for team with members did not (fully) work: " + refAuthorString + " <-> " + formatter.getTitleCache(team)+ " : " + refId);
|
1233
|
}
|
1234
|
}
|
1235
|
|
1236
|
private static void checkPerson(Person person, String refAuthorString, boolean hasDedupMember, Integer refId) {
|
1237
|
PersonDefaultCacheStrategy formatter = (PersonDefaultCacheStrategy) person.cacheStrategy();
|
1238
|
|
1239
|
String oldTitleCache = person.getTitleCache();
|
1240
|
boolean oldTitleCacheProtected = person.isProtectedTitleCache();
|
1241
|
|
1242
|
if (! oldTitleCache.equals(refAuthorString)){
|
1243
|
logger.error("Old titleCache does not equal refAuthorString this should not happen. "+ oldTitleCache + " <-> " + refAuthorString + "; refId = " + refId);
|
1244
|
}
|
1245
|
|
1246
|
boolean protect = true;
|
1247
|
person.setProtectedTitleCache(false);
|
1248
|
if (refAuthorString.equals(formatter.getTitleCache(person))){
|
1249
|
protect = false;
|
1250
|
}else if(formatter.getFullTitle(person).equals(refAuthorString)){
|
1251
|
//.. or teams with initials first
|
1252
|
protect = false;
|
1253
|
}else{
|
1254
|
//keep protected, see below
|
1255
|
}
|
1256
|
|
1257
|
if (hasDedupMember){
|
1258
|
//restore
|
1259
|
//TODO maybe even do not use dedup for testing
|
1260
|
person.setTitleCache(oldTitleCache, oldTitleCacheProtected);
|
1261
|
if (protect != oldTitleCacheProtected){
|
1262
|
logger.warn("Deduplicated person protection requirement unclear for "+refAuthorString+". New:"+protect+"/Old:"+oldTitleCacheProtected+"; RefId: " + refId);
|
1263
|
}
|
1264
|
}else{
|
1265
|
if (protect){
|
1266
|
logger.warn("Creation of titleCache for person (converted from team) with members did not (fully) work: " + refAuthorString + " <-> " + formatter.getTitleCache(person)+ " : " + refId);
|
1267
|
person.setTitleCache(refAuthorString, protect);
|
1268
|
}else{
|
1269
|
//keep unprotected
|
1270
|
}
|
1271
|
}
|
1272
|
}
|
1273
|
|
1274
|
private static boolean containsEdOrColon(String str) {
|
1275
|
if (str.contains(" ed.") || str.contains(" Ed.") || str.contains("(ed.")
|
1276
|
|| str.contains("[ed.") || str.contains("(Eds)") || str.contains("(Eds.)") ||
|
1277
|
str.contains("(eds.)") || str.contains(":")|| str.contains(";") || str.contains("Publ. & Inform. Directorate")
|
1278
|
|| str.contains("Anonymous [Department of Botany, Faculty of Science, FER-ZPR, University of Zagreb]")
|
1279
|
|| str.contains("Davis, P. H. (Güner, A. & al.)")){
|
1280
|
return true;
|
1281
|
}else{
|
1282
|
return false;
|
1283
|
}
|
1284
|
}
|
1285
|
|
1286
|
/**
|
1287
|
* @param nextSplit
|
1288
|
* @return
|
1289
|
*/
|
1290
|
private static boolean isInitial(String str) {
|
1291
|
if (str == null){
|
1292
|
return false;
|
1293
|
}
|
1294
|
boolean matches = str.trim().matches("(\\p{javaUpperCase}|Yu|Ya|Th|Ch|Lj|Sz|Dz|Sh|Ju|R. M. da S)\\.?"
|
1295
|
+ "(\\s*[-\\s]\\s*(\\p{javaUpperCase}|Yu|Ja|Kh|Tz|Ya|Th|Ju)\\.?)*(\\s+(van|von|de|de la|del|da|van der))?");
|
1296
|
return matches;
|
1297
|
}
|
1298
|
|
1299
|
private <T extends TeamOrPersonBase<?>> T deduplicatePersonOrTeam(BerlinModelImportState state,T author) {
|
1300
|
T result = state.getDeduplicationHelper().getExistingAuthor(author, true);
|
1301
|
return result;
|
1302
|
}
|
1303
|
|
1304
|
private Reference deduplicateReference(BerlinModelImportState state,Reference ref) {
|
1305
|
Reference result = state.getDeduplicationHelper().getExistingReference(ref, true);
|
1306
|
return result;
|
1307
|
}
|
1308
|
|
1309
|
private static Person makePerson(String full, boolean followedByInitial, Integer refId) {
|
1310
|
Person person = Person.NewInstance();
|
1311
|
person.setTitleCache(full, true);
|
1312
|
if (!full.matches(".*[\\s\\.].*")){
|
1313
|
person.setFamilyName(full);
|
1314
|
person.setProtectedTitleCache(false);
|
1315
|
}else{
|
1316
|
parsePerson(person, full, true, followedByInitial);
|
1317
|
}
|
1318
|
|
1319
|
if ((full.length() <= 2 && !full.matches("(Li|Bo|Em|Ay|Ma)")) || (full.length() == 3 && full.endsWith(".") && !full.equals("al.")) ){
|
1320
|
logger.warn("Unexpected short nom author name part: " + full + "; " + refId);
|
1321
|
}
|
1322
|
|
1323
|
return person;
|
1324
|
}
|
1325
|
|
1326
|
private static void parsePerson(Person person, String str, boolean preliminary, boolean followedByInitial) {
|
1327
|
String capWord = "\\p{javaUpperCase}\\p{javaLowerCase}{2,}";
|
1328
|
String famStart = "(Le |D'|'t |Mc|Mac|Des |d'|Du |De |Al-)";
|
1329
|
String regEx = "((\\p{javaUpperCase}|Ya|Th|Ju|Kh|An)\\.([\\s-]\\p{javaUpperCase}\\.)*(\\s(de|del|da|von|van|van der|v.|af|zu|von M. Und L.))?\\s)("
|
1330
|
+ famStart + "?" + capWord + "((-| y | i | é | de | de la )" + capWord + ")?)";
|
1331
|
Matcher matcher = Pattern.compile(regEx).matcher(str);
|
1332
|
if (matcher.matches()){
|
1333
|
person.setProtectedTitleCache(false);
|
1334
|
String familyName = matcher.group(6).trim();
|
1335
|
person.setFamilyName(familyName);
|
1336
|
person.setInitials(matcher.group(1).trim());
|
1337
|
}else{
|
1338
|
String regEx2 = "("+ capWord + "\\s" + capWord + "|Le Sueur|Beck von Mannagetta|Di Martino|Galán de Mera|Van Der Maesen|Farga i Arquimbau|Perez de Paz|Borzatti de Loewenstern|Lo Giudice|Perez de Paz)";
|
1339
|
Matcher matcher2 = Pattern.compile(regEx2).matcher(str);
|
1340
|
if (followedByInitial && matcher2.matches()){
|
1341
|
person.setFamilyName(str);
|
1342
|
person.setProtectedTitleCache(false);
|
1343
|
}else{
|
1344
|
person.setTitleCache(str, preliminary);
|
1345
|
}
|
1346
|
}
|
1347
|
}
|
1348
|
|
1349
|
private static boolean handleSimilarAuthors(BerlinModelImportState state, String refAuthorString,
|
1350
|
TeamOrPersonBase<?> nomAuthor, int refId) {
|
1351
|
String nomTitle = nomAuthor.getTitleCache();
|
1352
|
|
1353
|
if (refAuthorString.equals(nomAuthor.getNomenclaturalTitleCache())){
|
1354
|
//nomTitle equal
|
1355
|
return true;
|
1356
|
}else{
|
1357
|
if (refAuthorString.replace(" & ", ", ").equals(nomTitle.replace(" & ", ", "))){
|
1358
|
//nomTitle equal except for "&"
|
1359
|
return true;
|
1360
|
}
|
1361
|
String nomFullTitle = nomAuthor.getFullTitle();
|
1362
|
if (refAuthorString.replace(" & ", ", ").equals(nomFullTitle.replace(" & ", ", "))){
|
1363
|
return true;
|
1364
|
}
|
1365
|
|
1366
|
if (nomAuthor.isInstanceOf(Person.class)){
|
1367
|
Person person = CdmBase.deproxy(nomAuthor, Person.class);
|
1368
|
|
1369
|
//refAuthor has initials behind, nom Author in front // the other way round is handled in firstIsFullNameOfInitialName
|
1370
|
if (refAuthorString.contains(",") && !nomTitle.contains(",") ){
|
1371
|
String[] splits = refAuthorString.split(",");
|
1372
|
if (splits.length == 2){
|
1373
|
String newMatch = splits[1].trim() + " " + splits[0].trim();
|
1374
|
if (newMatch.equals(nomTitle)){
|
1375
|
if (isBlank(person.getFamilyName())){
|
1376
|
person.setFamilyName(splits[0].trim());
|
1377
|
}
|
1378
|
if (isBlank(person.getInitials())){
|
1379
|
person.setInitials(splits[1].trim());
|
1380
|
}
|
1381
|
return true;
|
1382
|
}
|
1383
|
}
|
1384
|
}
|
1385
|
|
1386
|
if (refAuthorIsFamilyAuthorOfNomAuthor(state, refAuthorString, person)){
|
1387
|
return true;
|
1388
|
}
|
1389
|
|
1390
|
if (firstIsFullNameOfInitialName(state, refAuthorString, person, refId)){
|
1391
|
return true;
|
1392
|
}
|
1393
|
}
|
1394
|
|
1395
|
}
|
1396
|
return false;
|
1397
|
}
|
1398
|
|
1399
|
/**
|
1400
|
* @param state
|
1401
|
* @param refAuthorString
|
1402
|
* @param person
|
1403
|
* @return
|
1404
|
*/
|
1405
|
private static boolean refAuthorIsFamilyAuthorOfNomAuthor(BerlinModelImportState state, String refAuthorString,
|
1406
|
Person person) {
|
1407
|
if (refAuthorString.equals(person.getFamilyName())){
|
1408
|
return true;
|
1409
|
}else{
|
1410
|
return false;
|
1411
|
}
|
1412
|
}
|
1413
|
|
1414
|
/**
|
1415
|
* @param state
|
1416
|
* @param refAuthorString
|
1417
|
* @param nomAuthor
|
1418
|
* @return
|
1419
|
*/
|
1420
|
private static boolean firstIsFullNameOfInitialName(BerlinModelImportState state, String fullName,
|
1421
|
Person initialAuthor, int refId) {
|
1422
|
String initialName = initialAuthor.getTitleCache();
|
1423
|
|
1424
|
String[] fullSplits = fullName.split(",");
|
1425
|
String[] initialSplits = initialName.split(",");
|
1426
|
|
1427
|
if (fullSplits.length == 2 && initialSplits.length == 2){
|
1428
|
String[] fullGivenName = fullSplits[1].trim().split(" ");
|
1429
|
String[] initialsGivenName = initialSplits[1].trim().split(" ");
|
1430
|
boolean result = compareFamilyAndInitials(fullSplits[0], initialSplits[0], fullGivenName, initialsGivenName);
|
1431
|
if (result){
|
1432
|
setGivenName(state, fullSplits[1], initialAuthor, refId);
|
1433
|
}
|
1434
|
return result;
|
1435
|
}else if (fullSplits.length == 1 && initialSplits.length == 2){
|
1436
|
String[] fullSingleSplits = fullName.split(" ");
|
1437
|
String fullFamily = fullSingleSplits[fullSingleSplits.length-1];
|
1438
|
String[] fullGivenName = Arrays.copyOfRange(fullSingleSplits, 0, fullSingleSplits.length-1);
|
1439
|
String[] initialsGivenName = initialSplits[1].trim().split(" ");
|
1440
|
boolean result = compareFamilyAndInitials(fullFamily, initialSplits[0], fullGivenName, initialsGivenName);
|
1441
|
if (result){
|
1442
|
if(hasAtLeastOneFullName(fullGivenName)){
|
1443
|
setGivenName(state, CdmUtils.concat(" ", fullGivenName), initialAuthor, refId);
|
1444
|
}
|
1445
|
}
|
1446
|
return result;
|
1447
|
}else if (fullSplits.length == 1 && initialAuthor.getInitials() == null){
|
1448
|
//don't if this will be implemented, initialAuthors with only nomencl.Author set
|
1449
|
}
|
1450
|
|
1451
|
return false;
|
1452
|
}
|
1453
|
|
1454
|
/**
|
1455
|
* @param fullGivenName
|
1456
|
* @return
|
1457
|
*/
|
1458
|
private static boolean hasAtLeastOneFullName(String[] fullGivenName) {
|
1459
|
for (String singleName : fullGivenName){
|
1460
|
if (!singleName.endsWith(".") && singleName.length() > 2 && !singleName.matches("(von|van)") ){
|
1461
|
return true;
|
1462
|
}
|
1463
|
}
|
1464
|
return false;
|
1465
|
}
|
1466
|
|
1467
|
private static void setGivenName(BerlinModelImportState state, String givenName, Person person, int refId) {
|
1468
|
givenName = givenName.trim();
|
1469
|
if(person.getGivenName() == null || person.getGivenName().equals(givenName)){
|
1470
|
person.setGivenName(givenName);
|
1471
|
}else{
|
1472
|
logger.warn("RefAuthor given name and existing given name differ: " + givenName + " <-> " + person.getGivenName() + "; RefId + " + refId);
|
1473
|
}
|
1474
|
}
|
1475
|
|
1476
|
protected static boolean compareFamilyAndInitials(String fullFamilyName, String initialsFamilyName,
|
1477
|
String[] fullGivenName, String[] initialsGivenName) {
|
1478
|
if (!fullFamilyName.equals(initialsFamilyName)){
|
1479
|
return false;
|
1480
|
}
|
1481
|
if (fullGivenName.length == initialsGivenName.length){
|
1482
|
for (int i =0; i< fullGivenName.length ; i++){
|
1483
|
if (fullGivenName[i].length() == 0 //comma ending not allowed
|
1484
|
|| initialsGivenName[i].length() != 2 //only K. or similar allowed
|
1485
|
|| fullGivenName[i].length() < initialsGivenName[i].length() //fullFirstName must be longer than abbrev Name
|
1486
|
|| !initialsGivenName[i].endsWith(".") //initials must end with "."
|
1487
|
|| !fullGivenName[i].startsWith(initialsGivenName[i].replace(".", ""))){ //start with same letter
|
1488
|
if (fullGivenName[i].matches("(von|van|de|zu)") && fullGivenName[i].equals(initialsGivenName[i])){
|
1489
|
continue;
|
1490
|
}else{
|
1491
|
return false;
|
1492
|
}
|
1493
|
}
|
1494
|
}
|
1495
|
return true;
|
1496
|
}else{
|
1497
|
return false;
|
1498
|
}
|
1499
|
}
|
1500
|
|
1501
|
public Set<String> getObligatoryAttributes(boolean lowerCase, BerlinModelImportConfigurator config){
|
1502
|
Set<String> result = new HashSet<>();
|
1503
|
Class<ICdmImport>[] ioClassList = config.getIoClassList();
|
1504
|
result.addAll(Arrays.asList(unclearMappers));
|
1505
|
result.addAll(Arrays.asList(createdAndNotesAttributes));
|
1506
|
result.addAll(Arrays.asList(operationalAttributes));
|
1507
|
CdmIoMapping mapping = new CdmIoMapping();
|
1508
|
for (CdmAttributeMapperBase mapper : classMappers){
|
1509
|
mapping.addMapper(mapper);
|
1510
|
}
|
1511
|
result.addAll(mapping.getSourceAttributes());
|
1512
|
if (lowerCase){
|
1513
|
Set<String> lowerCaseResult = new HashSet<>();
|
1514
|
for (String str : result){
|
1515
|
if (str != null){lowerCaseResult.add(str.toLowerCase());}
|
1516
|
}
|
1517
|
result = lowerCaseResult;
|
1518
|
}
|
1519
|
return result;
|
1520
|
}
|
1521
|
|
1522
|
@Override
|
1523
|
protected boolean doCheck(BerlinModelImportState state){
|
1524
|
BerlinModelReferenceImportValidator validator = new BerlinModelReferenceImportValidator();
|
1525
|
return validator.validate(state, this);
|
1526
|
}
|
1527
|
|
1528
|
@Override
|
1529
|
protected boolean isIgnore(BerlinModelImportState state){
|
1530
|
return (state.getConfig().getDoReferences() == IImportConfigurator.DO_REFERENCES.NONE);
|
1531
|
}
|
1532
|
|
1533
|
}
|