Revision 24921917
Added by Andreas Müller over 1 year ago
cdmlib-api/src/main/java/eu/etaxonomy/cdm/api/dto/portal/CdmBaseDto.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
//the taxon uuid |
21 | 21 |
//TODO move to base class |
22 |
public UUID uuid;
|
|
23 |
public int id;
|
|
22 |
private UUID uuid;
|
|
23 |
private int id;
|
|
24 | 24 |
|
25 | 25 |
//computed from updated of all relevant data |
26 | 26 |
//uses java.time.XXX to have less dependencies |
27 | 27 |
//TODO or should we use jodatime |
28 |
public LocalDateTime lastUpdated; |
|
28 |
private LocalDateTime lastUpdated; |
|
29 |
|
|
30 |
public UUID getUuid() { |
|
31 |
return uuid; |
|
32 |
} |
|
33 |
public void setUuid(UUID uuid) { |
|
34 |
this.uuid = uuid; |
|
35 |
} |
|
36 |
|
|
37 |
public int getId() { |
|
38 |
return id; |
|
39 |
} |
|
40 |
public void setId(int id) { |
|
41 |
this.id = id; |
|
42 |
} |
|
43 |
|
|
44 |
public LocalDateTime getLastUpdated() { |
|
45 |
return lastUpdated; |
|
46 |
} |
|
47 |
public void setLastUpdated(LocalDateTime lastUpdated) { |
|
48 |
this.lastUpdated = lastUpdated; |
|
49 |
} |
|
29 | 50 |
|
30 | 51 |
} |
cdmlib-api/src/main/java/eu/etaxonomy/cdm/api/dto/portal/FeatureDto.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2023 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.api.dto.portal; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.mueller |
|
13 |
* @date 10.01.2023 |
|
14 |
*/ |
|
15 |
public class FeatureDto extends CdmBaseDto { |
|
16 |
|
|
17 |
private String label; |
|
18 |
|
|
19 |
public String getLabel() { |
|
20 |
return label; |
|
21 |
} |
|
22 |
public void setLabel(String label) { |
|
23 |
this.label = label; |
|
24 |
} |
|
25 |
|
|
26 |
} |
cdmlib-api/src/main/java/eu/etaxonomy/cdm/api/dto/portal/TaxonBaseDto.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
//TODO should we distinguish data parts (e.g. on general page we do not need last updates from synonymy) |
20 | 20 |
//lastUpdated |
21 |
public String taxonLabel;
|
|
22 |
public String nameLabel;
|
|
21 |
private String taxonLabel;
|
|
22 |
private String nameLabel;
|
|
23 | 23 |
|
24 | 24 |
//TODO should we keep formatting client side or should we do formatting on server side? Formatting means: filter, italics, order?? |
25 |
public List<TypedLabel> typedTaxonLabel; |
|
26 |
public List<TypedLabel> typedNameLabel; |
|
25 |
private List<TypedLabel> typedTaxonLabel; |
|
26 |
private List<TypedLabel> typedNameLabel; |
|
27 |
|
|
28 |
public String getTaxonLabel() { |
|
29 |
return taxonLabel; |
|
30 |
} |
|
31 |
public void setTaxonLabel(String taxonLabel) { |
|
32 |
this.taxonLabel = taxonLabel; |
|
33 |
} |
|
34 |
|
|
35 |
public String getNameLabel() { |
|
36 |
return nameLabel; |
|
37 |
} |
|
38 |
public void setNameLabel(String nameLabel) { |
|
39 |
this.nameLabel = nameLabel; |
|
40 |
} |
|
41 |
|
|
42 |
public List<TypedLabel> getTypedTaxonLabel() { |
|
43 |
return typedTaxonLabel; |
|
44 |
} |
|
45 |
public void setTypedTaxonLabel(List<TypedLabel> typedTaxonLabel) { |
|
46 |
this.typedTaxonLabel = typedTaxonLabel; |
|
47 |
} |
|
48 |
|
|
49 |
public List<TypedLabel> getTypedNameLabel() { |
|
50 |
return typedNameLabel; |
|
51 |
} |
|
52 |
public void setTypedNameLabel(List<TypedLabel> typedNameLabel) { |
|
53 |
this.typedNameLabel = typedNameLabel; |
|
54 |
} |
|
27 | 55 |
|
28 | 56 |
//TaxonBase info |
29 | 57 |
//appendedPhras, useNameCache, doubtful, name, publish |
cdmlib-api/src/main/java/eu/etaxonomy/cdm/api/dto/portal/TaxonPageDto.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
public class TaxonPageDto extends TaxonBaseDto { |
20 | 20 |
|
21 |
public HomotypicGroupDTO homotypicSynonyms;
|
|
21 |
private HomotypicGroupDTO homotypicSynonyms;
|
|
22 | 22 |
|
23 |
public ContainerDto<TaxonNodeDTO> taxonNodes;
|
|
23 |
private ContainerDto<TaxonNodeDTO> taxonNodes;
|
|
24 | 24 |
|
25 |
public ContainerDto<HomotypicGroupDTO> heterotypicSynonyms;
|
|
25 |
private ContainerDto<HomotypicGroupDTO> heterotypicSynonyms;
|
|
26 | 26 |
|
27 |
public ContainerDto<FactualDataDTO> factualData;
|
|
27 |
private ContainerDto<FactualDataDTO> factualData;
|
|
28 | 28 |
|
29 |
public ContainerDto<KeyDTO> keys;
|
|
29 |
private ContainerDto<KeyDTO> keys;
|
|
30 | 30 |
|
31 |
public ContainerDto<SpecimenDTO> specimens;
|
|
31 |
private ContainerDto<SpecimenDTO> specimens;
|
|
32 | 32 |
|
33 |
public ContainerDto<MediaDTO> media;
|
|
33 |
private ContainerDto<MediaDTO> media;
|
|
34 | 34 |
|
35 |
public List<MessagesDto> messages;
|
|
35 |
private List<MessagesDto> messages;
|
|
36 | 36 |
|
37 | 37 |
//******************** subclasses *********************************/ |
38 | 38 |
|
... | ... | |
65 | 65 |
|
66 | 66 |
} |
67 | 67 |
|
68 |
public HomotypicGroupDTO getHomotypicSynonyms() { |
|
69 |
return homotypicSynonyms; |
|
70 |
} |
|
71 |
public void setHomotypicSynonyms(HomotypicGroupDTO homotypicSynonyms) { |
|
72 |
this.homotypicSynonyms = homotypicSynonyms; |
|
73 |
} |
|
74 |
|
|
75 |
public ContainerDto<TaxonNodeDTO> getTaxonNodes() { |
|
76 |
return taxonNodes; |
|
77 |
} |
|
78 |
public void setTaxonNodes(ContainerDto<TaxonNodeDTO> taxonNodes) { |
|
79 |
this.taxonNodes = taxonNodes; |
|
80 |
} |
|
81 |
|
|
82 |
public ContainerDto<HomotypicGroupDTO> getHeterotypicSynonyms() { |
|
83 |
return heterotypicSynonyms; |
|
84 |
} |
|
85 |
public void setHeterotypicSynonyms(ContainerDto<HomotypicGroupDTO> heterotypicSynonyms) { |
|
86 |
this.heterotypicSynonyms = heterotypicSynonyms; |
|
87 |
} |
|
88 |
|
|
89 |
public ContainerDto<FactualDataDTO> getFactualData() { |
|
90 |
return factualData; |
|
91 |
} |
|
92 |
public void setFactualData(ContainerDto<FactualDataDTO> factualData) { |
|
93 |
this.factualData = factualData; |
|
94 |
} |
|
95 |
|
|
96 |
public ContainerDto<KeyDTO> getKeys() { |
|
97 |
return keys; |
|
98 |
} |
|
99 |
public void setKeys(ContainerDto<KeyDTO> keys) { |
|
100 |
this.keys = keys; |
|
101 |
} |
|
102 |
|
|
103 |
public ContainerDto<SpecimenDTO> getSpecimens() { |
|
104 |
return specimens; |
|
105 |
} |
|
106 |
public void setSpecimens(ContainerDto<SpecimenDTO> specimens) { |
|
107 |
this.specimens = specimens; |
|
108 |
} |
|
109 |
|
|
110 |
public ContainerDto<MediaDTO> getMedia() { |
|
111 |
return media; |
|
112 |
} |
|
113 |
public void setMedia(ContainerDto<MediaDTO> media) { |
|
114 |
this.media = media; |
|
115 |
} |
|
116 |
|
|
117 |
public List<MessagesDto> getMessages() { |
|
118 |
return messages; |
|
119 |
} |
|
120 |
public void setMessages(List<MessagesDto> messages) { |
|
121 |
this.messages = messages; |
|
122 |
} |
|
123 |
|
|
124 |
|
|
68 | 125 |
|
69 | 126 |
|
70 | 127 |
|
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonPortalController.java | ||
---|---|---|
31 | 31 |
import org.springframework.web.bind.annotation.RequestMapping; |
32 | 32 |
import org.springframework.web.bind.annotation.RequestMethod; |
33 | 33 |
import org.springframework.web.bind.annotation.RequestParam; |
34 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
34 | 35 |
import org.springframework.web.servlet.ModelAndView; |
35 | 36 |
|
36 | 37 |
import eu.etaxonomy.cdm.api.dto.portal.TaxonPageDto; |
... | ... | |
305 | 306 |
@RequestMapping( |
306 | 307 |
value = {"page"}, |
307 | 308 |
method = RequestMethod.GET) |
308 |
public ModelAndView doGetTaxonPage(@PathVariable("uuid") UUID taxonUuid, |
|
309 |
@ResponseBody |
|
310 |
public TaxonPageDto doGetTaxonPage(@PathVariable("uuid") UUID taxonUuid, |
|
309 | 311 |
@RequestParam(value = "subtree", required = false) UUID subtreeUuid, |
310 | 312 |
//TODO configuration data |
311 | 313 |
HttpServletRequest request, |
... | ... | |
315 | 317 |
} |
316 | 318 |
|
317 | 319 |
//TODO is this current state of art? |
318 |
ModelAndView mv = new ModelAndView(); |
|
320 |
// ModelAndView mv = new ModelAndView();
|
|
319 | 321 |
|
320 | 322 |
//check taxon exists and not filtered |
321 | 323 |
Taxon taxon = getCdmBaseInstance(Taxon.class, taxonUuid, response, getTaxonNodeInitStrategy().getPropertyPaths()); |
... | ... | |
325 | 327 |
TaxonPageDtoConfiguration config = new TaxonPageDtoConfiguration(); |
326 | 328 |
config.taxonUuid = taxonUuid; |
327 | 329 |
TaxonPageDto dto = portalDtoService.taxonPageDto(config); |
328 |
mv.addObject(dto); |
|
329 |
return mv; |
|
330 |
return dto; |
|
330 | 331 |
} |
331 | 332 |
|
332 | 333 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/portal/PortalDtoLoader.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.api.service.portal; |
10 | 10 |
|
11 | 11 |
import java.time.LocalDateTime; |
12 |
import java.util.Set; |
|
13 |
import java.util.stream.Collectors; |
|
12 | 14 |
|
13 | 15 |
import org.joda.time.DateTime; |
14 | 16 |
|
17 |
import eu.etaxonomy.cdm.api.dto.portal.ContainerDto; |
|
18 |
import eu.etaxonomy.cdm.api.dto.portal.FeatureDto; |
|
15 | 19 |
import eu.etaxonomy.cdm.api.dto.portal.TaxonPageDto; |
16 | 20 |
import eu.etaxonomy.cdm.api.dto.portal.config.TaxonPageDtoConfiguration; |
17 | 21 |
import eu.etaxonomy.cdm.common.CdmUtils; |
18 | 22 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
23 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
19 | 24 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
20 | 25 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
21 | 26 |
|
... | ... | |
33 | 38 |
|
34 | 39 |
TaxonName name = taxon.getName(); |
35 | 40 |
|
36 |
result.id = taxon.getId(); |
|
37 |
result.uuid = taxon.getUuid(); |
|
38 |
result.lastUpdated = getLastUpdated(null, taxon); |
|
39 |
result.nameLabel = name != null? name.getTitleCache() : ""; |
|
40 |
result.taxonLabel = CdmUtils.Nz(taxon.getTitleCache()); |
|
41 |
result.setId(taxon.getId()); |
|
42 |
result.setUuid(taxon.getUuid()); |
|
43 |
result.setLastUpdated(getLastUpdated(null, taxon)); |
|
44 |
result.setNameLabel(name != null? name.getTitleCache() : ""); |
|
45 |
result.setTaxonLabel(CdmUtils.Nz(taxon.getTitleCache())); |
|
46 |
|
|
47 |
//TODO load feature tree |
|
48 |
// Set<Feature> featureSet = new HashSet<>(); |
|
49 |
Set<Feature> featureSet = taxon.getDescriptions().stream() |
|
50 |
.filter(d->!d.isImageGallery()) |
|
51 |
.flatMap(d->d.getElements().stream()) |
|
52 |
.map(el->el.getFeature()) |
|
53 |
.collect(Collectors.toSet()) |
|
54 |
; |
|
55 |
//TODO sort |
|
56 |
if (!featureSet.isEmpty()) { |
|
57 |
ContainerDto<TaxonPageDto.FactualDataDTO> factualData = new ContainerDto<>(); |
|
58 |
result.setFactualData(factualData); |
|
59 |
for (Feature feature : featureSet) { |
|
60 |
FeatureDto featureDto = new FeatureDto(); |
|
61 |
featureDto.setId(feature.getId()); |
|
62 |
featureDto.setUuid(feature.getUuid()); |
|
63 |
//TODO locale |
|
64 |
featureDto.setLabel(feature.getTitleCache()); |
|
65 |
} |
|
66 |
} |
|
41 | 67 |
|
42 | 68 |
return result; |
43 | 69 |
} |
... | ... | |
47 | 73 |
* and returns the resulting last date. |
48 | 74 |
*/ |
49 | 75 |
private LocalDateTime getLastUpdated(LocalDateTime existingLastDate, VersionableEntity dateToAddEntity) { |
50 |
DateTime dateToAdd = dateToAddEntity.getUpdated() != null ? dateToAddEntity.getUpdated() : dateToAddEntity.getCreated(); |
|
51 | 76 |
|
77 |
DateTime dateToAdd = dateToAddEntity.getUpdated() != null ? dateToAddEntity.getUpdated() : dateToAddEntity.getCreated(); |
|
52 | 78 |
|
53 | 79 |
LocalDateTime javaLocalDateTimeOfEntity = dateToAdd == null ? null: |
54 | 80 |
LocalDateTime.of(dateToAdd.getYear(), dateToAdd.getMonthOfYear(), |
55 | 81 |
dateToAdd.getDayOfMonth(), dateToAdd.getHourOfDay(), |
56 | 82 |
dateToAdd.getMinuteOfHour(), dateToAdd.getSecondOfMinute()); |
57 | 83 |
|
58 |
|
|
59 |
if (javaLocalDateTimeOfEntity == null || javaLocalDateTimeOfEntity.compareTo(existingLastDate) < 0) { |
|
84 |
if (existingLastDate == null) { |
|
85 |
return javaLocalDateTimeOfEntity; |
|
86 |
}else if (javaLocalDateTimeOfEntity == null || javaLocalDateTimeOfEntity.compareTo(existingLastDate) < 0) { |
|
60 | 87 |
return existingLastDate; |
61 | 88 |
}else { |
62 | 89 |
return javaLocalDateTimeOfEntity; |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/portal/PortalDtoServiceImpl.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
import eu.etaxonomy.cdm.api.dto.portal.TaxonPageDto; |
19 | 19 |
import eu.etaxonomy.cdm.api.dto.portal.config.TaxonPageDtoConfiguration; |
20 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
20 | 21 |
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao; |
22 |
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao; |
|
21 | 23 |
|
22 | 24 |
/** |
23 | 25 |
* @author a.mueller |
... | ... | |
30 | 32 |
@Autowired |
31 | 33 |
private ICdmGenericDao dao; |
32 | 34 |
|
35 |
@Autowired |
|
36 |
private ITaxonDao taxonDao; |
|
37 |
|
|
33 | 38 |
@Override |
34 | 39 |
public TaxonPageDto taxonPageDto(TaxonPageDtoConfiguration config) { |
35 |
TaxonPageDto dto = new TaxonPageDto(); |
|
40 |
|
|
41 |
PortalDtoLoader loader = new PortalDtoLoader(); |
|
42 |
Taxon taxon = (Taxon)taxonDao.load(config.taxonUuid); |
|
43 |
TaxonPageDto dto = null; |
|
44 |
try { |
|
45 |
dto = loader.load(taxon, config); |
|
46 |
} catch (Exception e) { |
|
47 |
// TODO Auto-generated catch block |
|
48 |
e.printStackTrace(); |
|
49 |
} |
|
50 |
if (dto != null) { |
|
51 |
return dto; |
|
52 |
} |
|
53 |
|
|
54 |
dto = new TaxonPageDto(); |
|
36 | 55 |
|
37 | 56 |
//taxon data |
38 | 57 |
String taxonHql = " SELECT t.id as id, t.uuid as uuid, t.titleCache as taxonLabel," |
... | ... | |
43 | 62 |
List<Object[]> hqlResult = dao.getHqlResult(taxonHql, new Object[] {config.taxonUuid}, Object[].class); |
44 | 63 |
dto.id = (int)hqlResult.get(0)[0]; |
45 | 64 |
dto.uuid = (UUID)hqlResult.get(0)[1]; |
46 |
dto.taxonLabel = (String)hqlResult.get(0)[2];
|
|
47 |
dto.nameLabel = (String)hqlResult.get(0)[3];
|
|
48 |
dto.typedTaxonLabel = null;
|
|
49 |
dto.typedNameLabel = null;
|
|
65 |
dto.setTaxonLabel((String)hqlResult.get(0)[2]);
|
|
66 |
dto.setNameLabel((String)hqlResult.get(0)[3]);
|
|
67 |
dto.setTypedTaxonLabel(null);
|
|
68 |
dto.setTypedNameLabel(null);
|
|
50 | 69 |
|
51 | 70 |
//taxonNodes |
52 | 71 |
|
Also available in: Unified diff
ref #10222 first version of a taxon page dto framework (cont.)