Revision 210b9aa6
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationDTO.java | ||
---|---|---|
16 | 16 |
import eu.etaxonomy.cdm.mock.Registration; |
17 | 17 |
import eu.etaxonomy.cdm.mock.RegistrationStatus; |
18 | 18 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
19 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
|
19 | 20 |
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference; |
20 | 21 |
import eu.etaxonomy.cdm.model.reference.Reference; |
21 | 22 |
import eu.etaxonomy.cdm.vaadin.util.TypeDesignationConverter; |
... | ... | |
36 | 37 |
|
37 | 38 |
private Set<Registration> blockedBy = new HashSet<>(); |
38 | 39 |
|
40 |
private TaxonNameBase<?, ?> typifiedName; |
|
41 |
|
|
39 | 42 |
/** |
40 | 43 |
* @param reg |
41 | 44 |
* @param typifiedName should be provided in for Registrations for TypeDesignations |
45 |
* @throws RegistrationValidationException in case of inconsistencies in the Registration |
|
42 | 46 |
*/ |
43 |
public RegistrationDTO(Registration reg, TaxonNameBase typifiedName) {
|
|
47 |
public RegistrationDTO(Registration reg) throws RegistrationValidationException {
|
|
44 | 48 |
|
45 | 49 |
this.reg = reg; |
46 | 50 |
|
... | ... | |
53 | 57 |
citationID = citation.getId(); |
54 | 58 |
} |
55 | 59 |
} else if(registrationType.isTypification()){ |
60 |
typifiedName = findTypifiedName(); |
|
56 | 61 |
summary = new TypeDesignationConverter(reg.getTypeDesignations(), typifiedName) |
57 | 62 |
.buildString().print(); |
58 | 63 |
if(!reg.getTypeDesignations().isEmpty()){ |
... | ... | |
67 | 72 |
} |
68 | 73 |
} |
69 | 74 |
|
75 |
|
|
76 |
|
|
77 |
/** |
|
78 |
* @return |
|
79 |
* @throws RegistrationValidationException |
|
80 |
*/ |
|
81 |
private TaxonNameBase<?,?> findTypifiedName() throws RegistrationValidationException { |
|
82 |
|
|
83 |
StringBuffer problems = new StringBuffer(); |
|
84 |
|
|
85 |
TaxonNameBase<?,?> typifiedName = null; |
|
86 |
|
|
87 |
for(TypeDesignationBase<?> typeDesignation : reg.getTypeDesignations()){ |
|
88 |
typeDesignation.getTypifiedNames(); |
|
89 |
if(typeDesignation.getTypifiedNames().isEmpty()){ |
|
90 |
|
|
91 |
//TODO instead throw RegistrationValidationException() |
|
92 |
problems.append(" - Missing typifiedName in " + typeDesignation.toString()).append("\n"); |
|
93 |
continue; |
|
94 |
} |
|
95 |
if(typeDesignation.getTypifiedNames().size() > 1){ |
|
96 |
//TODO instead throw RegistrationValidationException() |
|
97 |
problems.append(" - Multiple typifiedName in " + typeDesignation.toString()).append("\n"); |
|
98 |
continue; |
|
99 |
} |
|
100 |
if(typifiedName == null){ |
|
101 |
// remember |
|
102 |
typifiedName = typeDesignation.getTypifiedNames().iterator().next(); |
|
103 |
} else { |
|
104 |
// compare |
|
105 |
TaxonNameBase<?,?> otherTypifiedName = typeDesignation.getTypifiedNames().iterator().next(); |
|
106 |
if(typifiedName.getId() != otherTypifiedName.getId()){ |
|
107 |
//TODO instead throw RegistrationValidationException() |
|
108 |
problems.append(" - Multiple typifiedName in " + typeDesignation.toString()).append("\n"); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
if(problems.length() > 0){ |
|
114 |
throw new RegistrationValidationException("Inconsistent Registration entity. " + reg.toString() + " Problems:\n" + problems.toString()); |
|
115 |
} |
|
116 |
|
|
117 |
return typifiedName; |
|
118 |
} |
|
119 |
|
|
120 |
|
|
70 | 121 |
/** |
71 | 122 |
* @return the summary |
72 | 123 |
*/ |
Also available in: Unified diff
better WorkflowView title, validation, some EventListeners