1
|
/**
|
2
|
* Copyright (C) 2017 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.dataInserter;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.EnumSet;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.log4j.Level;
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.hibernate.Session;
|
23
|
import org.springframework.context.event.ContextRefreshedEvent;
|
24
|
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
|
25
|
import org.springframework.security.core.GrantedAuthority;
|
26
|
import org.springframework.transaction.TransactionStatus;
|
27
|
import org.springframework.transaction.annotation.Transactional;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.application.AbstractDataInserter;
|
30
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
31
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
32
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
33
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
34
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
35
|
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
|
36
|
import eu.etaxonomy.cdm.model.common.Group;
|
37
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
38
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
39
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
40
|
import eu.etaxonomy.cdm.model.name.Rank;
|
41
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
42
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
43
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
44
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.taxonGraph.AbstractHibernateTaxonGraphProcessor;
|
45
|
import eu.etaxonomy.cdm.persistence.dao.taxonGraph.TaxonGraphException;
|
46
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
47
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
|
48
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
|
49
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
50
|
import eu.etaxonomy.cdm.vaadin.model.registration.KindOfUnitTerms;
|
51
|
import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
|
52
|
|
53
|
///*
|
54
|
// * Can create missing registrations for names which have Extensions of the Type <code>IAPTRegdata.json</code>.
|
55
|
//* See https://dev.e-taxonomy.eu/redmine/issues/6621 for further details.
|
56
|
//* This feature can be activated by by supplying one of the following jvm command line arguments:
|
57
|
//* <ul>
|
58
|
//* <li><code>-DregistrationCreate=iapt</code>: create all iapt Registrations if missing</li>
|
59
|
//* <li><code>-DregistrationWipeout=iapt</code>: remove all iapt Registrations</li>
|
60
|
//* <li><code>-DregistrationWipeout=all</code>: remove all Registrations</li>
|
61
|
//* </ul>
|
62
|
//* The <code>-DregistrationWipeout</code> commands are executed before the <code>-DregistrationCreate</code> and will not change the name and type designations.
|
63
|
//*/
|
64
|
/**
|
65
|
* This feature can be activated by by supplying one of the following jvm command line arguments:
|
66
|
* <ul>
|
67
|
* <li><code>-DtaxonGraphCreate=true</code>: create taxon graph relations for all names below genus level</li>
|
68
|
* </ul>
|
69
|
*
|
70
|
* @author a.kohlbecker
|
71
|
* @since May 9, 2017
|
72
|
*
|
73
|
*/
|
74
|
public class RegistrationRequiredDataInserter extends AbstractDataInserter {
|
75
|
|
76
|
// protected static final String PARAM_NAME_CREATE = "registrationCreate";
|
77
|
//
|
78
|
// protected static final String PARAM_NAME_WIPEOUT = "registrationWipeout";
|
79
|
|
80
|
protected static final String TAXON_GRAPH_CREATE = "taxonGraphCreate";
|
81
|
|
82
|
protected static final UUID GROUP_SUBMITTER_UUID = UUID.fromString("c468c6a7-b96c-4206-849d-5a825f806d3e");
|
83
|
|
84
|
protected static final UUID GROUP_CURATOR_UUID = UUID.fromString("135210d3-3db7-4a81-ab36-240444637d45");
|
85
|
|
86
|
private static final EnumSet<CRUD> CREATE_READ = EnumSet.of(CRUD.CREATE, CRUD.READ);
|
87
|
private static final EnumSet<CRUD> CREATE_READ_UPDATE_DELETE = EnumSet.of(CRUD.CREATE, CRUD.READ, CRUD.UPDATE, CRUD.DELETE);
|
88
|
|
89
|
private static final Logger logger = Logger.getLogger(RegistrationRequiredDataInserter.class);
|
90
|
|
91
|
// private ExtensionType extensionTypeIAPTRegData;
|
92
|
|
93
|
Map<String, Institution> instituteMap = new HashMap<>();
|
94
|
|
95
|
public static boolean commandsExecuted = false;
|
96
|
|
97
|
private CdmRepository repo;
|
98
|
|
99
|
private boolean hasRun = false;
|
100
|
|
101
|
public void setCdmRepository(CdmRepository repo){
|
102
|
this.repo = repo;
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* {@inheritDoc}
|
107
|
*/
|
108
|
@Override
|
109
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
110
|
|
111
|
if(hasRun){
|
112
|
return;
|
113
|
}
|
114
|
|
115
|
runAsAuthentication(Role.ROLE_ADMIN);
|
116
|
|
117
|
insertRequiredData();
|
118
|
executeSuppliedCommands();
|
119
|
|
120
|
restoreAuthentication();
|
121
|
|
122
|
hasRun = true;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
*
|
127
|
*/
|
128
|
@Transactional
|
129
|
private void insertRequiredData() {
|
130
|
|
131
|
TransactionStatus txStatus = repo.startTransaction(false);
|
132
|
|
133
|
Role roleCuration = RolesAndPermissions.ROLE_CURATION;
|
134
|
if(repo.getGrantedAuthorityService().find(roleCuration.getUuid()) == null){
|
135
|
repo.getGrantedAuthorityService().saveOrUpdate(roleCuration.asNewGrantedAuthority());
|
136
|
}
|
137
|
|
138
|
Group groupCurator = repo.getGroupService().load(GROUP_CURATOR_UUID, Arrays.asList("grantedAuthorities"));
|
139
|
if(groupCurator == null){
|
140
|
groupCurator = Group.NewInstance();
|
141
|
groupCurator.setUuid(GROUP_CURATOR_UUID);
|
142
|
groupCurator.setName("Curator");
|
143
|
}
|
144
|
assureGroupHas(groupCurator, new CdmAuthority(CdmPermissionClass.REGISTRATION, CREATE_READ_UPDATE_DELETE).toString());
|
145
|
repo.getGroupService().saveOrUpdate(groupCurator);
|
146
|
|
147
|
Group groupSubmitter = repo.getGroupService().load(GROUP_SUBMITTER_UUID, Arrays.asList("grantedAuthorities"));
|
148
|
if(groupSubmitter == null){
|
149
|
groupSubmitter = Group.NewInstance();
|
150
|
groupSubmitter.setUuid(GROUP_SUBMITTER_UUID);
|
151
|
groupSubmitter.setName("Submitter");
|
152
|
}
|
153
|
assureGroupHas(groupSubmitter, new CdmAuthority(CdmPermissionClass.TAXONNAME, CREATE_READ).toString());
|
154
|
assureGroupHas(groupSubmitter, new CdmAuthority(CdmPermissionClass.TEAMORPERSONBASE, CREATE_READ).toString());
|
155
|
assureGroupHas(groupSubmitter, new CdmAuthority(CdmPermissionClass.REGISTRATION, CREATE_READ).toString());
|
156
|
assureGroupHas(groupSubmitter, new CdmAuthority(CdmPermissionClass.REFERENCE, CREATE_READ).toString());
|
157
|
assureGroupHas(groupSubmitter, new CdmAuthority(CdmPermissionClass.SPECIMENOROBSERVATIONBASE, CREATE_READ).toString());
|
158
|
assureGroupHas(groupSubmitter, new CdmAuthority(CdmPermissionClass.COLLECTION, CREATE_READ).toString());
|
159
|
repo.getGroupService().saveOrUpdate(groupSubmitter);
|
160
|
|
161
|
TermVocabulary<DefinedTerm> kindOfUnitVocabulary = repo.getVocabularyService().find(KindOfUnitTerms.KIND_OF_UNIT_VOCABULARY().getUuid());
|
162
|
if(repo.getVocabularyService().find(KindOfUnitTerms.KIND_OF_UNIT_VOCABULARY().getUuid()) == null){
|
163
|
kindOfUnitVocabulary = repo.getVocabularyService().save(KindOfUnitTerms.KIND_OF_UNIT_VOCABULARY());
|
164
|
}
|
165
|
|
166
|
DefinedTermBase kouSpecimen = repo.getTermService().find(KindOfUnitTerms.SPECIMEN().getUuid());
|
167
|
DefinedTermBase kouImage = repo.getTermService().find(KindOfUnitTerms.PUBLISHED_IMAGE().getUuid());
|
168
|
DefinedTermBase kouUnpublishedImage = repo.getTermService().find(KindOfUnitTerms.UNPUBLISHED_IMAGE().getUuid());
|
169
|
DefinedTermBase kouCulture = repo.getTermService().find(KindOfUnitTerms.CULTURE_METABOLIC_INACTIVE().getUuid());
|
170
|
|
171
|
if(kouSpecimen == null){
|
172
|
kouSpecimen = repo.getTermService().save(KindOfUnitTerms.SPECIMEN());
|
173
|
}
|
174
|
if(kouImage == null){
|
175
|
kouImage = repo.getTermService().save(KindOfUnitTerms.PUBLISHED_IMAGE());
|
176
|
}
|
177
|
if(kouUnpublishedImage == null){
|
178
|
kouUnpublishedImage = repo.getTermService().save(KindOfUnitTerms.UNPUBLISHED_IMAGE());
|
179
|
}
|
180
|
if(kouCulture == null){
|
181
|
kouCulture = repo.getTermService().save(KindOfUnitTerms.CULTURE_METABOLIC_INACTIVE());
|
182
|
}
|
183
|
|
184
|
Set<DefinedTerm> termInVocab = kindOfUnitVocabulary.getTerms();
|
185
|
List<DefinedTermBase> kouTerms = Arrays.asList(kouCulture, kouImage, kouSpecimen, kouUnpublishedImage);
|
186
|
|
187
|
for(DefinedTermBase t : kouTerms){
|
188
|
if(!termInVocab.contains(t)){
|
189
|
kindOfUnitVocabulary.addTerm((DefinedTerm)t);
|
190
|
}
|
191
|
}
|
192
|
|
193
|
repo.commitTransaction(txStatus);
|
194
|
|
195
|
}
|
196
|
|
197
|
private void assureGroupHas(Group group, String authorityString){
|
198
|
boolean authorityExists = false;
|
199
|
|
200
|
for(GrantedAuthority ga : group.getGrantedAuthorities()){
|
201
|
if((authorityExists = ga.getAuthority().equals(authorityString)) == true){
|
202
|
break;
|
203
|
}
|
204
|
}
|
205
|
if(!authorityExists){
|
206
|
group.addGrantedAuthority(findGrantedAuthority(authorityString));
|
207
|
}
|
208
|
}
|
209
|
|
210
|
private GrantedAuthorityImpl findGrantedAuthority(String authorityString){
|
211
|
GrantedAuthorityImpl ga = null;
|
212
|
try{
|
213
|
ga = repo.getGrantedAuthorityService().findAuthorityString(authorityString);
|
214
|
} catch (AuthenticationCredentialsNotFoundException e){
|
215
|
e.printStackTrace();
|
216
|
}
|
217
|
if(ga == null){
|
218
|
ga = GrantedAuthorityImpl.NewInstance(authorityString);
|
219
|
repo.getGrantedAuthorityService().save(ga);
|
220
|
}
|
221
|
return ga;
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
*
|
226
|
*/
|
227
|
private void executeSuppliedCommands() {
|
228
|
|
229
|
if(commandsExecuted){
|
230
|
// do not run twice
|
231
|
// a second run could take place during initialization of the web context
|
232
|
return;
|
233
|
}
|
234
|
commandsExecuted = true;
|
235
|
|
236
|
String taxonGraphCreate = System.getProperty(TAXON_GRAPH_CREATE);
|
237
|
|
238
|
if(taxonGraphCreate != null){
|
239
|
AbstractHibernateTaxonGraphProcessor processor = new AbstractHibernateTaxonGraphProcessor() {
|
240
|
|
241
|
@Override
|
242
|
public Session getSession() {
|
243
|
return repo.getSession();
|
244
|
}
|
245
|
};
|
246
|
logger.setLevel(Level.DEBUG);
|
247
|
int chunksize = 1000;
|
248
|
int pageIndex = 0;
|
249
|
TransactionStatus tx;
|
250
|
Pager<Taxon> taxonPage;
|
251
|
List<TaxonBase> taxa = new ArrayList<>();
|
252
|
logger.debug("======= fixing sec refrences =========");
|
253
|
while(true){
|
254
|
tx = repo.startTransaction(false);
|
255
|
taxonPage = repo.getTaxonService().page(Taxon.class, chunksize, pageIndex++, null, null);
|
256
|
if(taxonPage.getRecords().size() == 0){
|
257
|
repo.commitTransaction(tx);
|
258
|
break;
|
259
|
}
|
260
|
for(Taxon taxon : taxonPage.getRecords()){
|
261
|
taxon.setSec(processor.secReference());
|
262
|
repo.getTaxonService().saveOrUpdate(taxon);
|
263
|
}
|
264
|
repo.commitTransaction(tx);
|
265
|
}
|
266
|
|
267
|
logger.debug("======= creating taxon graph =========");
|
268
|
pageIndex = 0;
|
269
|
Pager<TaxonName> page;
|
270
|
while(true){
|
271
|
tx = repo.startTransaction(false);
|
272
|
page = repo.getNameService().page(null, chunksize, pageIndex++, null, null);
|
273
|
if(page.getRecords().size() == 0){
|
274
|
repo.commitTransaction(tx);
|
275
|
break;
|
276
|
}
|
277
|
logger.debug(TAXON_GRAPH_CREATE + ": chunk " + pageIndex + "/" + Math.ceil(page.getCount() / chunksize));
|
278
|
taxa = new ArrayList<>();
|
279
|
|
280
|
for(TaxonName name : page.getRecords()){
|
281
|
if(name.getRank() != null && name.getRank().isLower(Rank.GENUS())){
|
282
|
NomenclaturalStatusType illegitimType = findILegitimateStatusType(name);
|
283
|
if(illegitimType == null){
|
284
|
Taxon taxon;
|
285
|
try {
|
286
|
logger.debug("Processing name: " + name.getTitleCache() + " [" + name.getRank().getLabel() + "]");
|
287
|
taxon = processor.assureSingleTaxon(name);
|
288
|
processor.updateEdges(taxon);
|
289
|
taxa.add(taxon);
|
290
|
} catch (TaxonGraphException e) {
|
291
|
logger.error(e.getMessage());
|
292
|
}
|
293
|
} else {
|
294
|
logger.debug("Skipping illegitimate name: " + name.getTitleCache() + " " + illegitimType.getLabel() + " [" + name.getRank().getLabel() + "]");
|
295
|
}
|
296
|
} else {
|
297
|
logger.debug("Skipping name: " + name.getTitleCache() + " [" + (name.getRank() != null ? name.getRank().getLabel() : "NULL") + "]");
|
298
|
}
|
299
|
}
|
300
|
repo.getTaxonService().saveOrUpdate(taxa);
|
301
|
repo.commitTransaction(tx);
|
302
|
}
|
303
|
}
|
304
|
|
305
|
// String wipeoutCmd = System.getProperty(PARAM_NAME_WIPEOUT);
|
306
|
// String createCmd = System.getProperty(PARAM_NAME_CREATE);
|
307
|
//
|
308
|
// // ============ DELETE
|
309
|
// if(wipeoutCmd != null && wipeoutCmd.matches("iapt|all")){
|
310
|
//
|
311
|
// boolean onlyIapt = wipeoutCmd.equals("iapt");
|
312
|
// Set<UUID> deleteCandidates = new HashSet<UUID>();
|
313
|
//
|
314
|
// TransactionStatus tx = repo.startTransaction(true);
|
315
|
// List<Registration> allRegs = repo.getRegistrationService().list(null, null, null, null, null);
|
316
|
// for(Registration reg : allRegs){
|
317
|
// if(onlyIapt){
|
318
|
// try {
|
319
|
// @SuppressWarnings("unchecked")
|
320
|
// Set<String> extensions = reg.getName().getExtensions(getExtensionTypeIAPTRegData());
|
321
|
// if(reg.getUuid() != null){
|
322
|
// deleteCandidates.add(reg.getUuid());
|
323
|
// }
|
324
|
// } catch(NullPointerException e){
|
325
|
// // IGNORE
|
326
|
// }
|
327
|
// } else {
|
328
|
// if(reg.getUuid() != null){
|
329
|
// deleteCandidates.add(reg.getUuid());
|
330
|
// }
|
331
|
// }
|
332
|
// }
|
333
|
// repo.commitTransaction(tx);
|
334
|
// if(!deleteCandidates.isEmpty()){
|
335
|
// try {
|
336
|
// repo.getRegistrationService().delete(deleteCandidates);
|
337
|
// } catch (Exception e) {
|
338
|
// // MySQLIntegrityConstraintViolationException happens here every second run !!!
|
339
|
// logger.error(e);
|
340
|
// }
|
341
|
// }
|
342
|
// }
|
343
|
//
|
344
|
// // ============ CREATE
|
345
|
// int pageIndex = 0;
|
346
|
// if(createCmd != null && createCmd.equals("iapt")){
|
347
|
//
|
348
|
// DateTimeFormatter dateFormat1 = org.joda.time.format.DateTimeFormat.forPattern("dd.MM.yy").withPivotYear(1950);
|
349
|
// DateTimeFormatter dateFormat2 = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd").withPivotYear(1950);
|
350
|
//
|
351
|
// TransactionStatus tx = repo.startTransaction(false);
|
352
|
// while(true) {
|
353
|
// Pager<TaxonName> pager = repo.getNameService().page(null, 1000, pageIndex, null, null);
|
354
|
// if(pager.getRecords().isEmpty()){
|
355
|
// break;
|
356
|
// }
|
357
|
// List<Registration> newRegs = new ArrayList<>(pager.getRecords().size());
|
358
|
// for(TaxonName name : pager.getRecords()){
|
359
|
//
|
360
|
//
|
361
|
//
|
362
|
// Set<String> extensionValues = name.getExtensions(getExtensionTypeIAPTRegData());
|
363
|
//
|
364
|
// // there is for sure only one
|
365
|
// if(extensionValues.isEmpty()){
|
366
|
// continue;
|
367
|
// }
|
368
|
//
|
369
|
// logger.debug("IAPT Registration for " + name.getTitleCache() + " ...");
|
370
|
//
|
371
|
// String iaptJson = extensionValues.iterator().next();
|
372
|
// try {
|
373
|
//
|
374
|
// IAPTRegData iaptData = new ObjectMapper().readValue(iaptJson, IAPTRegData.class);
|
375
|
//
|
376
|
// if(iaptData.getRegId() == null){
|
377
|
// continue;
|
378
|
// }
|
379
|
//
|
380
|
// DateTime regDate = null;
|
381
|
// if(iaptData.getDate() != null){
|
382
|
// DateTimeFormatter dateFormat;
|
383
|
// if(iaptData.getDate().matches("\\d{4}-\\d{2}-\\d{2}")){
|
384
|
// dateFormat = dateFormat2;
|
385
|
// } else {
|
386
|
// dateFormat = dateFormat1;
|
387
|
// }
|
388
|
// try {
|
389
|
// regDate = dateFormat.parseDateTime(iaptData.getDate());
|
390
|
// regDate.getYear();
|
391
|
// } catch (Exception e) {
|
392
|
// logger.error("Error parsing date : " + iaptData.getDate(), e);
|
393
|
// continue;
|
394
|
// }
|
395
|
// }
|
396
|
//
|
397
|
// Registration reg = Registration.NewInstance();
|
398
|
// reg.setStatus(RegistrationStatus.PUBLISHED);
|
399
|
// reg.setIdentifier("http://phycobank.org/" + iaptData.getRegId());
|
400
|
// reg.setSpecificIdentifier(iaptData.getRegId().toString());
|
401
|
// reg.setInstitution(getInstitution(iaptData.getOffice()));
|
402
|
//
|
403
|
// boolean isPhycobankID = Integer.valueOf(reg.getSpecificIdentifier()) >= 100000;
|
404
|
//
|
405
|
// Partial youngestDate = null;
|
406
|
// Reference youngestPub = null;
|
407
|
//
|
408
|
// // find youngest publication
|
409
|
//
|
410
|
// // NOTE:
|
411
|
// // data imported from IAPT does not have typedesignation citations and sometimes no nomref
|
412
|
//
|
413
|
// if(isPhycobankID){
|
414
|
// youngestPub = name.getNomenclaturalReference();
|
415
|
// youngestDate = partial(youngestPub.getDatePublished());
|
416
|
//
|
417
|
// if(name.getTypeDesignations() != null && !name.getTypeDesignations().isEmpty()){
|
418
|
// for(TypeDesignationBase<?> td : name.getTypeDesignations()){
|
419
|
// if(td.getCitation() == null){
|
420
|
// continue;
|
421
|
// }
|
422
|
// Partial pubdate = partial(td.getCitation().getDatePublished());
|
423
|
// if(pubdate != null){
|
424
|
//
|
425
|
// try {
|
426
|
// if(youngestDate== null || earlierThanOther(youngestDate, pubdate)){
|
427
|
// youngestDate = pubdate;
|
428
|
// youngestPub = td.getCitation();
|
429
|
// }
|
430
|
// } catch (Exception e) {
|
431
|
// logger.error("Error comparing " + youngestDate + " with" + pubdate , e);
|
432
|
// }
|
433
|
// }
|
434
|
// }
|
435
|
// }
|
436
|
// }
|
437
|
//
|
438
|
// if((isPhycobankID && youngestPub == name.getNomenclaturalReference()) || !isPhycobankID) {
|
439
|
// reg.setName(name);
|
440
|
// } else {
|
441
|
// logger.debug("skipping name published in older referece");
|
442
|
// }
|
443
|
// if(name.getTypeDesignations() != null && !name.getTypeDesignations().isEmpty()){
|
444
|
// // do not add the collection directly to avoid "Found shared references to a collection" problem
|
445
|
// Set<TypeDesignationBase> typeDesignations = new HashSet<>(name.getTypeDesignations().size());
|
446
|
// for(TypeDesignationBase<?> td : name.getTypeDesignations()){
|
447
|
// if(td.getCitation() == null && isPhycobankID){
|
448
|
// logger.error("Missing TypeDesignation Citation in Phycobank data");
|
449
|
// continue;
|
450
|
// }
|
451
|
// if((isPhycobankID && youngestPub == td.getCitation()) || !isPhycobankID){
|
452
|
// typeDesignations.add(td);
|
453
|
// } else {
|
454
|
// logger.debug("skipping typedesignation published in older reference");
|
455
|
// }
|
456
|
// }
|
457
|
// reg.setTypeDesignations(typeDesignations);
|
458
|
// }
|
459
|
// reg.setRegistrationDate(regDate);
|
460
|
// newRegs.add(reg);
|
461
|
//
|
462
|
// } catch (JsonParseException e) {
|
463
|
// logger.error("Error parsing IAPTRegData from extension", e);
|
464
|
// } catch (JsonMappingException e) {
|
465
|
// logger.error("Error mapping json from extension to IAPTRegData", e);
|
466
|
// } catch (IOException e) {
|
467
|
// logger.error(e);
|
468
|
// }
|
469
|
//
|
470
|
// }
|
471
|
// repo.getRegistrationService().save(newRegs);
|
472
|
// tx.flush();
|
473
|
// logger.debug("Registrations saved");
|
474
|
// pageIndex++;
|
475
|
// }
|
476
|
// repo.commitTransaction(tx);
|
477
|
// }
|
478
|
|
479
|
}
|
480
|
|
481
|
private NomenclaturalStatusType findILegitimateStatusType(TaxonName name){
|
482
|
for(NomenclaturalStatus status : name.getStatus()){
|
483
|
if(status.getType() != null && !status.getType().isLegitimateType()){
|
484
|
return status.getType();
|
485
|
}
|
486
|
}
|
487
|
return null;
|
488
|
}
|
489
|
|
490
|
|
491
|
// /**
|
492
|
// * @param youngestDate
|
493
|
// * @param pubdate
|
494
|
// * @return
|
495
|
// */
|
496
|
// private boolean earlierThanOther(Partial basePartial, Partial other) {
|
497
|
//
|
498
|
// if(basePartial == null || basePartial.getValues().length == 0){
|
499
|
// return false;
|
500
|
// }
|
501
|
// if(other == null || other.getValues().length == 0){
|
502
|
// return true;
|
503
|
// }
|
504
|
// if(basePartial.size() == other.size()) {
|
505
|
// return basePartial.compareTo(other) < 0;
|
506
|
// }
|
507
|
// basePartial = basePartial.without(DateTimeFieldType.dayOfMonth());
|
508
|
// other = other.without(DateTimeFieldType.dayOfMonth());
|
509
|
// if(basePartial.size() == other.size()) {
|
510
|
// return basePartial.compareTo(other) < 0;
|
511
|
// }
|
512
|
// basePartial = basePartial.without(DateTimeFieldType.monthOfYear());
|
513
|
// other = other.without(DateTimeFieldType.monthOfYear());
|
514
|
// return basePartial.compareTo(other) < 0;
|
515
|
//
|
516
|
// }
|
517
|
|
518
|
|
519
|
// /**
|
520
|
// * @param datePublished
|
521
|
// * @return
|
522
|
// */
|
523
|
// private Partial partial(TimePeriod datePublished) {
|
524
|
// if(datePublished != null){
|
525
|
// if(datePublished.getEnd() != null){
|
526
|
// return datePublished.getEnd();
|
527
|
// } else {
|
528
|
// return datePublished.getStart();
|
529
|
// }
|
530
|
// }
|
531
|
// return null;
|
532
|
// }
|
533
|
|
534
|
|
535
|
// /**
|
536
|
// * @param office
|
537
|
// * @return
|
538
|
// */
|
539
|
// private Institution getInstitution(String office) {
|
540
|
// Institution institution;
|
541
|
// if(instituteMap.containsKey(office)){
|
542
|
// institution = instituteMap.get(office);
|
543
|
// } else {
|
544
|
//
|
545
|
// Pager<Institution> pager = repo.getAgentService().findByTitleWithRestrictions(Institution.class, office, MatchMode.EXACT, null, null, null, null, null);
|
546
|
// ) if(!pager.getRecords().isEmpty()){
|
547
|
// institution = pager.getRecords().get(0);
|
548
|
// } else {
|
549
|
// Institution institute = (Institution) repo.getAgentService().save(Institution.NewNamedInstance(office));
|
550
|
// institution = institute;
|
551
|
// }
|
552
|
// instituteMap.put(office, institution);
|
553
|
// }
|
554
|
// return institution;
|
555
|
// }
|
556
|
|
557
|
|
558
|
// private ExtensionType getExtensionTypeIAPTRegData() {
|
559
|
// if(extensionTypeIAPTRegData == null){
|
560
|
// extensionTypeIAPTRegData = (ExtensionType) repo.getTermService().load(UUID.fromString("9be1bfe3-6ba0-4560-af15-86971ab96e09"));
|
561
|
// }
|
562
|
// return extensionTypeIAPTRegData;
|
563
|
// }
|
564
|
|
565
|
|
566
|
}
|