Revision 2d981b4e
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/RegistrationWorkingSet.java | ||
---|---|---|
14 | 14 |
import java.util.Set; |
15 | 15 |
|
16 | 16 |
import eu.etaxonomy.cdm.mock.Registration; |
17 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
17 | 18 |
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO; |
18 | 19 |
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationValidationException; |
19 | 20 |
|
... | ... | |
24 | 25 |
*/ |
25 | 26 |
public class RegistrationWorkingSet { |
26 | 27 |
|
27 |
private Set<Registration> registrations = new HashSet<>();
|
|
28 |
private List<RegistrationDTO> registrationDTOs = new ArrayList<>();
|
|
28 | 29 |
|
29 | 30 |
private int citationId = -1; |
30 | 31 |
|
31 | 32 |
private String citation = null; |
32 | 33 |
|
33 |
public RegistrationWorkingSet(Set<Registration> registrations) throws RegistrationValidationException { |
|
34 |
/** |
|
35 |
* Creates an empty working set |
|
36 |
*/ |
|
37 |
public RegistrationWorkingSet() { |
|
38 |
|
|
39 |
} |
|
34 | 40 |
|
35 |
validateAndAdd(registrations); |
|
41 |
public RegistrationWorkingSet(List<RegistrationDTO> registrationDTOs) throws RegistrationValidationException { |
|
42 |
validateAndAddDTOs(registrationDTOs, null); |
|
36 | 43 |
} |
37 | 44 |
|
38 | 45 |
/** |
... | ... | |
40 | 47 |
* @throws RegistrationValidationException |
41 | 48 |
* |
42 | 49 |
*/ |
43 |
private void validateAndAdd(Set<Registration> candidated) throws RegistrationValidationException { |
|
44 |
List<String> problems = new ArrayList<>(); |
|
45 |
for(Registration reg : candidated){ |
|
46 |
try { |
|
47 |
RegistrationDTO regDto = new RegistrationDTO(reg); |
|
50 |
private void validateAndAdd(Set<Registration> candidates) throws RegistrationValidationException { |
|
51 |
List<RegistrationDTO> dtos = new ArrayList<>(registrationDTOs.size()); |
|
52 |
candidates.forEach(reg -> dtos.add(new RegistrationDTO(reg))); |
|
53 |
validateAndAddDTOs(dtos, null); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Validate and add all Registrations to the working set which are referring to the same publication |
|
58 |
* which is either the citation of the nomenclatural reference of the {@link TaxonNameBase} or the |
|
59 |
* citation of the {@link TypeDesignations}. Registration with a differing publication are not added to |
|
60 |
* the working set, instead a {@link RegistrationValidationException} is thrown which is a container for |
|
61 |
* all validation problems. |
|
62 |
* |
|
63 |
* @param candidates |
|
64 |
* @param problems Problems detected in prior validation and processing passed to this method to be completed. |
|
65 |
* @throws RegistrationValidationException |
|
66 |
*/ |
|
67 |
private void validateAndAddDTOs(List<RegistrationDTO> candidates, List<String> problems) throws RegistrationValidationException { |
|
68 |
if(problems == null){ |
|
69 |
problems = new ArrayList<>(); |
|
70 |
} |
|
71 |
for(RegistrationDTO regDto : candidates){ |
|
48 | 72 |
if(citationId == -1){ |
49 | 73 |
citationId = regDto.getCitationID(); |
50 | 74 |
citation = regDto.getCitation(); |
51 | 75 |
} else { |
52 | 76 |
if(regDto.getCitationID() != citationId){ |
53 |
problems.add("Removing Registration " + reg.toString() + " from set since this refers to a different citation.\n");
|
|
77 |
problems.add("Removing Registration " + regDto.registration().toString() + " from set since this refers to a different citation.");
|
|
54 | 78 |
continue; |
55 | 79 |
} |
56 | 80 |
} |
57 |
this.registrations.add(reg); |
|
58 |
|
|
59 |
} catch (RegistrationValidationException e) { |
|
60 |
problems.add(e.getMessage()); |
|
61 |
} |
|
81 |
this.registrationDTOs.add(regDto); |
|
62 | 82 |
} |
63 | 83 |
|
64 | 84 |
if(!problems.isEmpty()){ |
65 |
throw new RegistrationValidationException(problems.toString());
|
|
85 |
throw new RegistrationValidationException("", problems);
|
|
66 | 86 |
} |
67 | 87 |
|
68 | 88 |
} |
69 | 89 |
|
70 |
public boolean add(Registration registration){ |
|
71 |
return registrations.add(registration); |
|
90 |
/** |
|
91 |
* @param reg |
|
92 |
* @throws RegistrationValidationException |
|
93 |
*/ |
|
94 |
public void add(Registration reg) throws RegistrationValidationException { |
|
95 |
Set<Registration> candidates = new HashSet<>(); |
|
96 |
candidates.add(reg); |
|
97 |
validateAndAdd(candidates); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* @return the registrations |
|
102 |
*/ |
|
103 |
public List<Registration> getRegistrations() { |
|
104 |
List<Registration> regs = new ArrayList<>(registrationDTOs.size()); |
|
105 |
registrationDTOs.forEach(dto -> regs.add(dto.registration())); |
|
106 |
return regs; |
|
72 | 107 |
} |
73 | 108 |
|
74 | 109 |
/** |
75 | 110 |
* @return the registrations |
76 | 111 |
*/ |
77 |
public Set<Registration> getRegistrations() {
|
|
78 |
return registrations; |
|
112 |
public List<RegistrationDTO> getRegistrationDTOs() {
|
|
113 |
return registrationDTOs;
|
|
79 | 114 |
} |
80 | 115 |
|
81 | 116 |
/** |
... | ... | |
94 | 129 |
|
95 | 130 |
|
96 | 131 |
|
132 |
|
|
97 | 133 |
} |
Also available in: Unified diff
ref #6169 RegistrationWorkingSets more complete, validation problems accessible via UI