Revision 260760a2
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/RegistrationWorkingSet.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
import eu.etaxonomy.cdm.model.name.Registration; |
21 | 21 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
22 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
23 | 22 |
import eu.etaxonomy.cdm.model.reference.Reference; |
23 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
|
24 | 24 |
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO; |
25 | 25 |
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationValidationException; |
26 | 26 |
|
... | ... | |
37 | 37 |
|
38 | 38 |
private DateTime created = null; |
39 | 39 |
|
40 |
private String citation = null; |
|
40 |
private String citationString = null;
|
|
41 | 41 |
|
42 | 42 |
/** |
43 | 43 |
* Creates an empty working set |
44 | 44 |
*/ |
45 | 45 |
public RegistrationWorkingSet(Reference citation) { |
46 | 46 |
citationId = citation.getId(); |
47 |
this.citation= citation.getTitleCache(); |
|
47 |
this.citationString= citation.getTitleCache();
|
|
48 | 48 |
|
49 | 49 |
} |
50 | 50 |
|
... | ... | |
66 | 66 |
/** |
67 | 67 |
* Validate and add all Registrations to the working set which are referring to the same publication |
68 | 68 |
* which is either the citation of the nomenclatural reference of the {@link TaxonName} or the |
69 |
* citation of the {@link TypeDesignations}. Registration with a differing publication are not added to |
|
69 |
* citation of the {@link TypeDesignations}. In case the citation is a section and this section is |
|
70 |
* having an in-reference the in-reference will be used instead. |
|
71 |
* Registration with a differing publication are not added to |
|
70 | 72 |
* the working set, instead a {@link RegistrationValidationException} is thrown which is a container for |
71 | 73 |
* all validation problems. |
72 | 74 |
* |
... | ... | |
80 | 82 |
problems = new ArrayList<>(); |
81 | 83 |
} |
82 | 84 |
for(RegistrationDTO regDto : candidates){ |
85 |
Reference citation = publicationUnit(regDto); |
|
83 | 86 |
if(citationId == null){ |
84 |
citationId = regDto.getCitationID();
|
|
85 |
citation = regDto.getCitation().getTitleCache();
|
|
87 |
citationId = citation.getId();
|
|
88 |
citationString = citation.getTitleCache();
|
|
86 | 89 |
} else { |
87 |
if(!regDto.getCitationID().equals(citationId)){
|
|
88 |
problems.add("Removing Registration " + regDto.getSummary() + " from set since this refers to a different citation."); |
|
90 |
if(citation.getId() != citationId.intValue()){
|
|
91 |
problems.add("Removing Registration " + regDto.getSummary() + " from set since this refers to a different citationString.");
|
|
89 | 92 |
continue; |
90 | 93 |
} |
91 | 94 |
} |
... | ... | |
101 | 104 |
|
102 | 105 |
} |
103 | 106 |
|
107 |
/** |
|
108 |
* @param regDto |
|
109 |
* @return |
|
110 |
*/ |
|
111 |
protected Reference publicationUnit(RegistrationDTO regDto) { |
|
112 |
Reference ref = regDto.getCitation(); |
|
113 |
while(ref.isOfType(ReferenceType.Section)&& ref.getInReference() != null){ |
|
114 |
ref = ref.getInReference(); |
|
115 |
if(!ref.isOfType(ReferenceType.Section)){ |
|
116 |
break; |
|
117 |
} |
|
118 |
} |
|
119 |
return ref; |
|
120 |
} |
|
121 |
|
|
104 | 122 |
/** |
105 | 123 |
* @param reg |
106 | 124 |
* @throws RegistrationValidationException |
... | ... | |
174 | 192 |
} |
175 | 193 |
|
176 | 194 |
/** |
177 |
* @return the citation |
|
195 |
* @return the citationString
|
|
178 | 196 |
*/ |
179 | 197 |
public String getCitation() { |
180 |
return citation; |
|
198 |
return citationString;
|
|
181 | 199 |
} |
182 | 200 |
|
183 | 201 |
public DateTime getRegistrationDate() { |
src/test/java/eu/etaxonomy/cdm/vaadin/model/RegistrationWorkingSetTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 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.vaadin.model; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 |
import org.junit.Assert; |
|
17 |
import org.junit.Test; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
20 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
21 |
import eu.etaxonomy.cdm.model.name.Registration; |
|
22 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
23 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
24 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
|
25 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
26 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
28 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
29 |
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet; |
|
30 |
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO; |
|
31 |
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationValidationException; |
|
32 |
|
|
33 |
/** |
|
34 |
* @author a.kohlbecker |
|
35 |
* @since Jan 11, 2018 |
|
36 |
* |
|
37 |
*/ |
|
38 |
public class RegistrationWorkingSetTest { |
|
39 |
|
|
40 |
@Test |
|
41 |
public void test_2_names() throws RegistrationValidationException { |
|
42 |
|
|
43 |
Reference article = ReferenceFactory.newArticle(); |
|
44 |
article.setTitleCache("Article", true); |
|
45 |
article.setId(1); |
|
46 |
|
|
47 |
Reference section = ReferenceFactory.newSection(); |
|
48 |
section.setTitleCache("Section", true); |
|
49 |
section.setInReference(article); |
|
50 |
section.setId(2); |
|
51 |
|
|
52 |
TaxonName name1 = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Amphora", null, "exemplaris", null, null, article, null, null); |
|
53 |
TaxonName name2 = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Amphora", null, "nonsensis", null, null, section, null, null); |
|
54 |
Registration reg1 = Registration.NewInstance("http://phycobank/0001", "0001", name1, null); |
|
55 |
Registration reg2 = Registration.NewInstance("http://phycobank/0002", "0002", name2, null); |
|
56 |
|
|
57 |
List<RegistrationDTO> dtos = new ArrayList<>(); |
|
58 |
dtos.add(new RegistrationDTO(reg1)); |
|
59 |
dtos.add(new RegistrationDTO(reg2)); |
|
60 |
|
|
61 |
RegistrationWorkingSet ws = new RegistrationWorkingSet(dtos); |
|
62 |
Assert.assertEquals(article.getId(), ws.getCitationId().intValue()); |
|
63 |
Assert.assertEquals(2, ws.getRegistrations().size()); |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
@Test |
|
68 |
public void test_name_and_type() throws RegistrationValidationException { |
|
69 |
|
|
70 |
Reference article = ReferenceFactory.newArticle(); |
|
71 |
article.setTitleCache("Article", true); |
|
72 |
article.setId(1); |
|
73 |
|
|
74 |
Reference section = ReferenceFactory.newSection(); |
|
75 |
section.setTitleCache("Section", true); |
|
76 |
section.setInReference(article); |
|
77 |
section.setId(2); |
|
78 |
|
|
79 |
Reference olderArticle = ReferenceFactory.newArticle(); |
|
80 |
olderArticle.setTitleCache("Older article", true); |
|
81 |
olderArticle.setId(1); |
|
82 |
|
|
83 |
TaxonName name1 = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Amphora", null, "exemplaris", null, null, olderArticle, null, null); |
|
84 |
SpecimenTypeDesignation std = SpecimenTypeDesignation.NewInstance(); |
|
85 |
std.setCitation(article); |
|
86 |
std.setTypeSpecimen(DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen)); |
|
87 |
Set<TypeDesignationBase> typeDesignations = new HashSet<>(); |
|
88 |
name1.addTypeDesignation(std, false); |
|
89 |
typeDesignations.add(std); |
|
90 |
TaxonName name2 = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Amphora", null, "nonsensis", null, null, section, null, null); |
|
91 |
Registration reg1 = Registration.NewInstance("http://phycobank/0001", "0001", null, typeDesignations); |
|
92 |
Registration reg2 = Registration.NewInstance("http://phycobank/0002", "0002", name2, null); |
|
93 |
|
|
94 |
List<RegistrationDTO> dtos = new ArrayList<>(); |
|
95 |
dtos.add(new RegistrationDTO(reg1)); |
|
96 |
dtos.add(new RegistrationDTO(reg2)); |
|
97 |
|
|
98 |
RegistrationWorkingSet ws = new RegistrationWorkingSet(dtos); |
|
99 |
Assert.assertEquals(article.getId(), ws.getCitationId().intValue()); |
|
100 |
Assert.assertEquals(2, ws.getRegistrations().size()); |
|
101 |
} |
|
102 |
|
|
103 |
} |
Also available in: Unified diff
fix #7169 RegistrationWorkingSet supports sections and adding test