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.service;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
import java.util.Optional;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.beans.factory.annotation.Qualifier;
|
19
|
import org.springframework.stereotype.Service;
|
20
|
import org.springframework.transaction.annotation.Transactional;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
23
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
24
|
import eu.etaxonomy.cdm.model.common.User;
|
25
|
import eu.etaxonomy.cdm.model.name.Registration;
|
26
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
29
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
|
30
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationValidationException;
|
31
|
|
32
|
/**
|
33
|
* Provides RegistrationDTOs and RegistrationWorkingsets for Registrations in the database.
|
34
|
* <p>
|
35
|
* Can create missing registrations for names which have Extensions of the Type <code>IAPTRegdata.json</code>.
|
36
|
* See https://dev.e-taxonomy.eu/redmine/issues/6621 for further details.
|
37
|
* This feature can be activated by by supplying one of the following jvm command line arguments:
|
38
|
* <ul>
|
39
|
* <li><code>-DregistrationCreate=iapt</code>: create all iapt Registrations if missing</li>
|
40
|
* <li><code>-DregistrationWipeout=iapt</code>: remove all iapt Registrations</li>
|
41
|
* <li><code>-DregistrationWipeout=all</code>: remove all Registrations</li>
|
42
|
* </ul>
|
43
|
* The <code>-DregistrationWipeout</code> commands are executed before the <code>-DregistrationCreate</code> and will not change the name and type designations.
|
44
|
*
|
45
|
*
|
46
|
* @author a.kohlbecker
|
47
|
* @since Mar 10, 2017
|
48
|
*
|
49
|
*/
|
50
|
@Service("registrationWorkingSetService")
|
51
|
@Transactional(readOnly=true)
|
52
|
public class RegistrationWorkingSetService implements IRegistrationWorkingSetService {
|
53
|
|
54
|
/**
|
55
|
*
|
56
|
*/
|
57
|
private static final int PAGE_SIZE = 50;
|
58
|
|
59
|
private static final Logger logger = Logger.getLogger(RegistrationWorkingSetService.class);
|
60
|
|
61
|
@Autowired
|
62
|
@Qualifier("cdmRepository")
|
63
|
private CdmRepository repo;
|
64
|
|
65
|
public RegistrationWorkingSetService() {
|
66
|
|
67
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
* @param id the CDM Entity id
|
72
|
* @return
|
73
|
*/
|
74
|
@Override
|
75
|
public RegistrationDTO loadDtoById(Integer id) {
|
76
|
Registration reg = repo.getRegistrationService().find(id);
|
77
|
return new RegistrationDTO(reg);
|
78
|
}
|
79
|
|
80
|
|
81
|
@Override
|
82
|
public Collection<RegistrationDTO> listDTOs() {
|
83
|
|
84
|
List<Registration> regs = repo.getRegistrationService().list(null, PAGE_SIZE, 0, null, null);
|
85
|
|
86
|
List<RegistrationDTO> dtos = makeDTOs(regs);
|
87
|
return dtos;
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* {@inheritDoc}
|
92
|
*/
|
93
|
@Override
|
94
|
public Collection<RegistrationDTO> listDTOs(User submitter, Collection<RegistrationStatus> includedStatus) {
|
95
|
|
96
|
Pager<Registration> pager = repo.getRegistrationService().page(submitter, includedStatus, PAGE_SIZE, 0, null, null);
|
97
|
return makeDTOs(pager.getRecords());
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* {@inheritDoc}
|
102
|
* @throws RegistrationValidationException
|
103
|
*/
|
104
|
@Override
|
105
|
@Deprecated
|
106
|
public RegistrationWorkingSet loadWorkingSetByReferenceID(Integer referenceID) throws RegistrationValidationException {
|
107
|
|
108
|
Reference reference = repo.getReferenceService().find(referenceID);
|
109
|
Pager<Registration> pager = repo.getRegistrationService().page(Optional.of(reference), null, null, null, null);
|
110
|
return new RegistrationWorkingSet(makeDTOs(pager.getRecords()));
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
public RegistrationWorkingSet loadWorkingSetByCitationID(Integer id) throws RegistrationValidationException {
|
115
|
|
116
|
Reference ref = repo.getReferenceService().find(id);
|
117
|
Pager<Registration> pager = repo.getRegistrationService().page(Optional.of(ref), null, null, null, null);
|
118
|
return new RegistrationWorkingSet(makeDTOs(pager.getRecords()));
|
119
|
}
|
120
|
|
121
|
|
122
|
/**
|
123
|
* @param regs
|
124
|
* @return
|
125
|
*/
|
126
|
private List<RegistrationDTO> makeDTOs(List<Registration> regs) {
|
127
|
List<RegistrationDTO> dtos = new ArrayList<>(regs.size());
|
128
|
regs.forEach(reg -> {dtos.add(new RegistrationDTO(reg));});
|
129
|
return dtos;
|
130
|
}
|
131
|
|
132
|
|
133
|
|
134
|
|
135
|
|
136
|
|
137
|
}
|