Revision a6584bc2
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/mock/Registration.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.mock; |
10 | 10 |
|
11 |
import java.util.Collection; |
|
11 | 12 |
import java.util.HashSet; |
12 | 13 |
import java.util.Set; |
13 | 14 |
|
... | ... | |
158 | 159 |
this.submitter = submitter; |
159 | 160 |
} |
160 | 161 |
|
161 |
public boolean addTypeDesignationBase(TypeDesignationBase typeDesignationBase){ |
|
162 |
return typeDesignations.add(typeDesignationBase); |
|
162 |
public boolean addTypeDesignation(TypeDesignationBase typeDesignation){ |
|
163 |
return this.typeDesignations.add(typeDesignation); |
|
164 |
} |
|
165 |
|
|
166 |
public boolean addTypeDesignations(Collection<TypeDesignationBase> typeDesignations){ |
|
167 |
return this.typeDesignations.addAll(typeDesignations); |
|
163 | 168 |
} |
164 | 169 |
|
165 | 170 |
public boolean addBlockedBy(Registration registration){ |
src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.Collection; |
12 | 12 |
import java.util.HashMap; |
13 |
import java.util.HashSet; |
|
13 | 14 |
import java.util.List; |
14 | 15 |
import java.util.Map; |
15 | 16 |
import java.util.UUID; |
... | ... | |
18 | 19 |
|
19 | 20 |
import org.springframework.beans.factory.annotation.Autowired; |
20 | 21 |
import org.springframework.beans.factory.annotation.Qualifier; |
21 |
import org.springframework.stereotype.Component; |
|
22 |
import org.springframework.stereotype.Service; |
|
23 |
import org.springframework.transaction.TransactionStatus; |
|
24 |
import org.springframework.transaction.annotation.Transactional; |
|
22 | 25 |
|
23 | 26 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
27 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
28 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
24 | 29 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
25 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
|
30 |
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationDTO;
|
|
26 | 31 |
|
27 | 32 |
/** |
28 | 33 |
* @author a.kohlbecker |
29 | 34 |
* @since Mar 10, 2017 |
30 | 35 |
* |
31 | 36 |
*/ |
32 |
@Component("registrationServiceMock") |
|
37 |
@Service("registrationServiceMock") |
|
38 |
@Transactional |
|
33 | 39 |
public class RegistrationService { |
34 | 40 |
|
35 | 41 |
@Autowired |
... | ... | |
38 | 44 |
|
39 | 45 |
private Map<UUID, Registration> registrationsByUUID = new HashMap<>(); |
40 | 46 |
private Map<String, Registration> registrationsByRegID = new HashMap<>(); |
47 |
private Map<String, RegistrationDTO> registrationDTOsByRegID = new HashMap<>(); |
|
48 |
|
|
49 |
private Collection<CdmBase> cdmEntities = new HashSet<>(); |
|
41 | 50 |
|
42 | 51 |
public RegistrationService() { |
43 | 52 |
} |
44 | 53 |
|
54 |
|
|
55 |
int minTypeDesignationCount = 1; |
|
56 |
|
|
45 | 57 |
@PostConstruct |
46 | 58 |
protected void init(){ |
47 |
List<TaxonNameBase> names = repo.getNameService().list(TaxonNameBase.class, 20, 0, null, null); |
|
48 |
names.forEach( |
|
49 |
name -> { |
|
50 |
Registration reg = new Registration(); |
|
51 |
reg.setName(name); |
|
52 |
registrationsByUUID.put(reg.getUuid(), reg); |
|
53 |
registrationsByRegID.put(reg.getSpecificIdentifier(), reg); |
|
59 |
TransactionStatus tx = repo.startTransaction(true); |
|
60 |
while(registrationsByUUID.size() < 20){ |
|
61 |
List<TaxonNameBase> names = repo.getNameService(). list(TaxonNameBase.class, 100, 0, null, null); |
|
62 |
for(TaxonNameBase name : names){ |
|
63 |
if(name.getRank().isLower(Rank.SUBFAMILY())){ |
|
64 |
if(name.getTypeDesignations().size() > minTypeDesignationCount - 1) { |
|
65 |
|
|
66 |
// name |
|
67 |
Registration nameReg = new Registration(); |
|
68 |
nameReg.setName(name); |
|
69 |
cdmEntities.add(name); |
|
70 |
put(nameReg, new RegistrationDTO(nameReg, null)); |
|
71 |
|
|
72 |
// typedesignation |
|
73 |
Registration typedesignationReg = new Registration(); |
|
74 |
typedesignationReg.addTypeDesignations(name.getTypeDesignations()); |
|
75 |
cdmEntities.addAll(name.getTypeDesignations()); |
|
76 |
put(typedesignationReg, new RegistrationDTO(typedesignationReg, name)); |
|
77 |
} |
|
54 | 78 |
} |
55 |
); |
|
56 |
List<TypeDesignationBase> tds = repo.getNameService().getAllTypeDesignations(20, 0); |
|
57 |
tds.forEach( |
|
58 |
type -> { |
|
59 |
Registration reg = new Registration(); |
|
60 |
reg.addTypeDesignationBase(type); |
|
61 |
registrationsByUUID.put(reg.getUuid(), reg); |
|
62 |
registrationsByRegID.put(reg.getSpecificIdentifier(), reg); |
|
63 |
} |
|
64 |
); |
|
79 |
} |
|
80 |
} |
|
81 |
repo.commitTransaction(tx); |
|
82 |
} |
|
65 | 83 |
|
84 |
/** |
|
85 |
* @param reg |
|
86 |
*/ |
|
87 |
private void put(Registration reg, RegistrationDTO dto) { |
|
88 |
registrationsByUUID.put(reg.getUuid(), reg); |
|
89 |
registrationsByRegID.put(reg.getSpecificIdentifier(), reg); |
|
90 |
registrationDTOsByRegID.put(reg.getSpecificIdentifier(), dto); |
|
66 | 91 |
} |
67 | 92 |
|
93 |
private void mergeBack(){ |
|
94 |
cdmEntities.forEach(e -> repo.getNameService().getSession().merge(e)); |
|
95 |
} |
|
68 | 96 |
|
69 | 97 |
/** |
70 | 98 |
* {@inheritDoc} |
... | ... | |
77 | 105 |
return registrationsByUUID.values(); |
78 | 106 |
} |
79 | 107 |
|
108 |
public Collection<RegistrationDTO> listDTOs() { |
|
109 |
return registrationDTOsByRegID.values(); |
|
110 |
} |
|
80 | 111 |
|
81 | 112 |
/** |
82 | 113 |
* @param registrationID |
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/phycobank/ListPresenter.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.vaadin.presenter.phycobank; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
12 | 11 |
import java.util.Collection; |
13 | 12 |
|
14 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
16 | 15 |
import com.vaadin.spring.annotation.SpringComponent; |
17 | 16 |
import com.vaadin.spring.annotation.ViewScope; |
18 | 17 |
|
19 |
import eu.etaxonomy.cdm.mock.Registration; |
|
20 | 18 |
import eu.etaxonomy.cdm.mock.RegistrationService; |
21 | 19 |
import eu.etaxonomy.cdm.vaadin.view.phycobank.ListView; |
22 | 20 |
import eu.etaxonomy.vaadin.mvp.AbstractPresenter; |
... | ... | |
43 | 41 |
* @return |
44 | 42 |
*/ |
45 | 43 |
private Collection<RegistrationDTO> listRegistrations() { |
46 |
Collection<Registration> registrations = serviceMock.list(); |
|
47 |
Collection<RegistrationDTO> dtos = new ArrayList<>(registrations.size()); |
|
48 |
registrations.forEach(reg -> { dtos.add(new RegistrationDTO(reg)); }); |
|
44 |
Collection<RegistrationDTO> dtos = serviceMock.listDTOs(); |
|
49 | 45 |
return dtos; |
50 | 46 |
} |
51 | 47 |
|
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/phycobank/RegistrationDTO.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import eu.etaxonomy.cdm.mock.Registration; |
14 | 14 |
import eu.etaxonomy.cdm.mock.RegistrationStatus; |
15 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
16 |
import eu.etaxonomy.cdm.vaadin.util.TypeDesignationConverter; |
|
15 | 17 |
|
16 | 18 |
public class RegistrationDTO{ |
17 | 19 |
|
... | ... | |
25 | 27 |
|
26 | 28 |
/** |
27 | 29 |
* @param reg |
30 |
* @param typifiedName should be provided in for Registrations for TypeDesignations |
|
28 | 31 |
*/ |
29 |
public RegistrationDTO(Registration reg) { |
|
32 |
public RegistrationDTO(Registration reg, TaxonNameBase typifiedName) {
|
|
30 | 33 |
|
31 | 34 |
this.reg = reg; |
32 | 35 |
|
... | ... | |
34 | 37 |
if(registrationType.isName()){ |
35 | 38 |
summary = reg.getName().getTitleCache(); |
36 | 39 |
} else if(registrationType.isTypification()){ |
37 |
StringBuffer sb = new StringBuffer(); |
|
38 |
reg.getTypeDesignations().forEach(td -> sb.append(td.toString()).append(' ')); |
|
39 |
summary = sb.toString(); |
|
40 |
summary = new TypeDesignationConverter(reg.getTypeDesignations(), typifiedName) |
|
41 |
.buildString().print(); |
|
40 | 42 |
} else { |
41 | 43 |
summary = "- INVALID REGISTRATION -"; |
42 | 44 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/TypeDesignationConverter.java | ||
---|---|---|
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.vaadin.util; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.Collections; |
|
14 |
import java.util.Comparator; |
|
15 |
import java.util.HashMap; |
|
16 |
import java.util.LinkedList; |
|
17 |
import java.util.List; |
|
18 |
import java.util.Map; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.model.common.Language; |
|
21 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignation; |
|
22 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
23 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; |
|
24 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
25 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
|
26 |
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; |
|
27 |
|
|
28 |
/** |
|
29 |
* Converts a collection of TypeDesignations, which should belong to the |
|
30 |
* same name of course, into a string representation. |
|
31 |
* |
|
32 |
* Order of TypeDesignations in the resulting string: |
|
33 |
* Type, Holotype, Lectotype, Epitypes |
|
34 |
* @author a.kohlbecker |
|
35 |
* @since Mar 10, 2017 |
|
36 |
* |
|
37 |
*/ |
|
38 |
public class TypeDesignationConverter { |
|
39 |
|
|
40 |
|
|
41 |
private final String separator = ", "; |
|
42 |
|
|
43 |
private Collection<TypeDesignationBase> typeDesignations; |
|
44 |
private Map<TypeDesignationStatusBase<?>, Collection<String>> orderedStrings; |
|
45 |
|
|
46 |
private String finalString = null; |
|
47 |
|
|
48 |
private String typifiedNameCache = null; |
|
49 |
|
|
50 |
/** |
|
51 |
* @param taxonNameBase |
|
52 |
* |
|
53 |
*/ |
|
54 |
public TypeDesignationConverter(Collection<TypeDesignationBase> typeDesignations, TaxonNameBase taxonNameBase) { |
|
55 |
this.typeDesignations = typeDesignations; |
|
56 |
orderedStrings = new HashMap<>(typeDesignations.size()); |
|
57 |
if(taxonNameBase != null){ |
|
58 |
this.typifiedNameCache = taxonNameBase.getTitleCache(); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
private void putString(TypeDesignationStatusBase<?> status, String string){ |
|
63 |
// the cdm orderd term bases are ordered invers, fixing this for here |
|
64 |
if(status == null){ |
|
65 |
status = SpecimenTypeDesignationStatus.TYPE(); |
|
66 |
} |
|
67 |
if(!orderedStrings.containsKey(status)){ |
|
68 |
orderedStrings.put(status, new ArrayList<String>()); |
|
69 |
} |
|
70 |
orderedStrings.get(status).add(string); |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
public TypeDesignationConverter buildString(){ |
|
75 |
|
|
76 |
typeDesignations.forEach(td -> putString(td.getTypeStatus(), stringify(td))); |
|
77 |
|
|
78 |
StringBuilder sb = new StringBuilder(); |
|
79 |
|
|
80 |
if(typifiedNameCache != null){ |
|
81 |
sb.append(typifiedNameCache).append(": "); |
|
82 |
} |
|
83 |
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(orderedStrings.keySet()); |
|
84 |
|
|
85 |
Collections.sort(keyList, new Comparator<TypeDesignationStatusBase>() { |
|
86 |
@Override |
|
87 |
public int compare(TypeDesignationStatusBase o1, TypeDesignationStatusBase o2) { |
|
88 |
// fix inverted order of cdm terms by -1* |
|
89 |
return -1 * o1.compareTo(o2); |
|
90 |
} |
|
91 |
}); |
|
92 |
|
|
93 |
keyList.forEach(key -> { |
|
94 |
if(key.equals( SpecimenTypeDesignationStatus.TYPE())){ |
|
95 |
sb.append("Type"); |
|
96 |
} else { |
|
97 |
sb.append(key.getPreferredRepresentation(Language.DEFAULT())); |
|
98 |
} |
|
99 |
sb.append(": "); |
|
100 |
orderedStrings.get(key).forEach(str -> { |
|
101 |
sb.append(str); |
|
102 |
if(sb.length() > 0){ |
|
103 |
sb.append(separator); |
|
104 |
} |
|
105 |
}); |
|
106 |
}); |
|
107 |
|
|
108 |
finalString = sb.toString(); |
|
109 |
return this; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* @param td |
|
114 |
* @return |
|
115 |
*/ |
|
116 |
private String stringify(TypeDesignationBase td) { |
|
117 |
|
|
118 |
if(td instanceof NameTypeDesignation){ |
|
119 |
return stringify((NameTypeDesignation)td); |
|
120 |
} else { |
|
121 |
return stringify((SpecimenTypeDesignation)td); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
/** |
|
127 |
* @param td |
|
128 |
* @return |
|
129 |
*/ |
|
130 |
protected String stringify(NameTypeDesignation td) { |
|
131 |
|
|
132 |
StringBuffer sb = new StringBuffer(); |
|
133 |
|
|
134 |
if(td.getTypeName() != null){ |
|
135 |
sb.append(td.getTypeName().getTitleCache()); |
|
136 |
} |
|
137 |
if(td.getCitation() != null){ |
|
138 |
sb.append(" ").append(td.getCitation().getTitleCache()); |
|
139 |
if(td.getCitationMicroReference() != null){ |
|
140 |
sb.append(":").append(td.getCitationMicroReference()); |
|
141 |
} |
|
142 |
} |
|
143 |
if(td.isNotDesignated()){ |
|
144 |
sb.append(" not designated"); |
|
145 |
} |
|
146 |
if(td.isRejectedType()){ |
|
147 |
sb.append(" rejected"); |
|
148 |
} |
|
149 |
if(td.isConservedType()){ |
|
150 |
sb.append(" conserved"); |
|
151 |
} |
|
152 |
return sb.toString(); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* @param td |
|
157 |
* @return |
|
158 |
*/ |
|
159 |
private String stringify(SpecimenTypeDesignation td) { |
|
160 |
StringBuffer sb = new StringBuffer(); |
|
161 |
|
|
162 |
if(td.getTypeSpecimen() != null){ |
|
163 |
String nameTitleCache = td.getTypeSpecimen().getTitleCache(); |
|
164 |
if(typifiedNameCache != null){ |
|
165 |
nameTitleCache = nameTitleCache.replace(typifiedNameCache, ""); |
|
166 |
} |
|
167 |
sb.append(nameTitleCache); |
|
168 |
} |
|
169 |
|
|
170 |
if(td.getCitation() != null){ |
|
171 |
sb.append(" ").append(td.getCitation().getTitleCache()); |
|
172 |
if(td.getCitationMicroReference() != null){ |
|
173 |
sb.append(" :").append(td.getCitationMicroReference()); |
|
174 |
} |
|
175 |
} |
|
176 |
if(td.isNotDesignated()){ |
|
177 |
sb.append(" not designated"); |
|
178 |
} |
|
179 |
|
|
180 |
return sb.toString(); |
|
181 |
} |
|
182 |
|
|
183 |
public String print(){ |
|
184 |
return finalString; |
|
185 |
} |
|
186 |
} |
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss | ||
---|---|---|
199 | 199 |
} |
200 | 200 |
} |
201 | 201 |
|
202 |
|
|
203 |
|
|
202 | 204 |
} |
src/test/java/eu/etaxonomy/cdm/vaadin/util/TypeDesignationConverterTest.java | ||
---|---|---|
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.vaadin.util; |
|
10 |
|
|
11 |
import static org.junit.Assert.assertNotNull; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.junit.Test; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignation; |
|
20 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
21 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
22 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; |
|
23 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
24 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
|
25 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
|
26 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
27 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
28 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
29 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
30 |
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author a.kohlbecker |
|
34 |
* @since Mar 10, 2017 |
|
35 |
* |
|
36 |
*/ |
|
37 |
public class TypeDesignationConverterTest extends CdmVaadinBaseTest{ |
|
38 |
|
|
39 |
|
|
40 |
@Test |
|
41 |
public void test1(){ |
|
42 |
|
|
43 |
NameTypeDesignation ntd = NameTypeDesignation.NewInstance(); |
|
44 |
TaxonNameBase typeName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES()); |
|
45 |
typeName.setTitleCache("Prionus coriatius L.", true); |
|
46 |
ntd.setTypeName(typeName); |
|
47 |
Reference citation = ReferenceFactory.newGeneric(); |
|
48 |
citation.setTitleCache("Species Platarum", true); |
|
49 |
ntd.setCitation(citation); |
|
50 |
|
|
51 |
SpecimenTypeDesignation std = SpecimenTypeDesignation.NewInstance(); |
|
52 |
DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen); |
|
53 |
specimen.setTitleCache("OHA", true); |
|
54 |
std.setTypeSpecimen(specimen); |
|
55 |
std.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE()); |
|
56 |
|
|
57 |
List<TypeDesignationBase> tds = new ArrayList<>(); |
|
58 |
tds.add(ntd); |
|
59 |
tds.add(std); |
|
60 |
|
|
61 |
String result = new TypeDesignationConverter(tds, null).buildString().print(); |
|
62 |
Logger.getLogger(this.getClass()).debug(result); |
|
63 |
assertNotNull(result); |
|
64 |
} |
|
65 |
|
|
66 |
} |
Also available in: Unified diff
ref #6169 compact string representations for registrations