1
|
package eu.etaxonomy.cdm.remote.vaadin.components;
|
2
|
|
3
|
import java.util.Arrays;
|
4
|
import java.util.Collection;
|
5
|
import java.util.List;
|
6
|
|
7
|
import javax.annotation.PostConstruct;
|
8
|
import javax.sql.DataSource;
|
9
|
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.hibernate.SessionFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.context.annotation.Scope;
|
14
|
import org.springframework.orm.hibernate4.HibernateTransactionManager;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
|
17
|
import com.vaadin.data.util.BeanItemContainer;
|
18
|
import com.vaadin.ui.Table;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
22
|
import eu.etaxonomy.cdm.api.service.INameService;
|
23
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
24
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
25
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
26
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
29
|
import eu.etaxonomy.cdm.remote.dto.redlist.RedlistDTO;
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
* This class is a Vaadin Component. It starts a long running session at the moment.
|
34
|
* This might change in the future, but for now it beautifully works for this prototype.<p>
|
35
|
* This class takes advantage of the dto and fills a container with data from the DB. Lazyloading or
|
36
|
* Paging needs to be used!!!!
|
37
|
* <p>
|
38
|
* Further clarification is needed about the exact process when marking this component as dirty.
|
39
|
* What will happen to the bound session? Why are changed Object saved without calling services explicitly.
|
40
|
*
|
41
|
*
|
42
|
* @author a.oppermann
|
43
|
*
|
44
|
*/
|
45
|
|
46
|
@Component
|
47
|
@Scope("request")
|
48
|
public class TaxonTableDTO extends Table{
|
49
|
|
50
|
/**
|
51
|
* automatic generated ID
|
52
|
*/
|
53
|
@Autowired
|
54
|
ITaxonService taxonService;
|
55
|
@Autowired
|
56
|
INameService nameService;
|
57
|
@Autowired
|
58
|
IDescriptionService descriptionService;
|
59
|
@Autowired
|
60
|
ITermService termService;
|
61
|
|
62
|
@Autowired
|
63
|
private HibernateTransactionManager transactionManager;
|
64
|
|
65
|
@Autowired
|
66
|
private DataSource dataSource;
|
67
|
|
68
|
@Autowired
|
69
|
private SessionFactory sessionFactory;
|
70
|
|
71
|
private ConversationHolder conversationHolder;
|
72
|
|
73
|
|
74
|
Logger logger = Logger.getLogger(TaxonTableDTO.class);
|
75
|
|
76
|
private static final long serialVersionUID = -8449485694571526437L;
|
77
|
|
78
|
@PostConstruct
|
79
|
@SuppressWarnings("rawtypes")
|
80
|
void PostConstruct(){
|
81
|
setSizeFull();
|
82
|
|
83
|
// conversationHolder = new ConversationHolder(dataSource, sessionFactory, transactionManager);
|
84
|
// conversationHolder.bind();
|
85
|
final BeanItemContainer<RedlistDTO> redListContainer = new BeanItemContainer<RedlistDTO>(RedlistDTO.class);
|
86
|
//TODO: Make use of paging
|
87
|
Collection<Taxon> listTaxon = taxonService.list(Taxon.class, null, null, null, NODE_INIT_STRATEGY);
|
88
|
|
89
|
for(Taxon taxonBase:listTaxon){
|
90
|
|
91
|
Taxon taxon = (Taxon) taxonBase;
|
92
|
List<PresenceAbsenceTermBase> termList = termService.listByTermClass(PresenceAbsenceTermBase.class, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
93
|
List<DescriptionElementBase> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, null, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
94
|
RedlistDTO redlistDTO = new RedlistDTO(taxon, listTaxonDescription, termList);
|
95
|
redListContainer.addBean(redlistDTO);
|
96
|
}
|
97
|
|
98
|
|
99
|
setContainerDataSource(redListContainer);
|
100
|
setColumnReorderingAllowed(true);
|
101
|
|
102
|
String[] columns = new String[]{"fullTitleCache", "rank", "UUID", "distributionStatus"};
|
103
|
setVisibleColumns(columns);
|
104
|
setColumnHeaders(new String[]{"Taxon", "Rang" , "UUID", "Deutschland"});
|
105
|
setImmediate(true);
|
106
|
setColumnCollapsingAllowed(true);
|
107
|
setSelectable(true);
|
108
|
setSizeFull();
|
109
|
setPageLength(10);
|
110
|
}
|
111
|
|
112
|
public ConversationHolder getConversationHolder() {
|
113
|
return conversationHolder;
|
114
|
}
|
115
|
|
116
|
|
117
|
private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[]{
|
118
|
"descriptions",
|
119
|
"descriptions.*",
|
120
|
"description.state",
|
121
|
"feature",
|
122
|
"feature.*",
|
123
|
"childNodes",
|
124
|
"childNodes.taxon",
|
125
|
"childNodes.taxon.name",
|
126
|
"taxonNodes",
|
127
|
"taxonNodes.*",
|
128
|
"taxonNodes.taxon.*",
|
129
|
"taxon.*",
|
130
|
"taxon.descriptions",
|
131
|
"taxon.sec",
|
132
|
"taxon.name.*",
|
133
|
"taxon.synonymRelations",
|
134
|
"terms",
|
135
|
"name.*",
|
136
|
"name.rank.representations",
|
137
|
"name.status.type.representations",
|
138
|
"sources.$",
|
139
|
"stateData.$"
|
140
|
});
|
141
|
|
142
|
protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
143
|
"$",
|
144
|
"elements.*",
|
145
|
"elements.sources.citation.authorTeam.$",
|
146
|
"elements.sources.nameUsedInSource.originalNameString",
|
147
|
"elements.area.level",
|
148
|
"elements.modifyingText",
|
149
|
"elements.states.*",
|
150
|
"elements.media",
|
151
|
"elements.multilanguageText",
|
152
|
"multilanguageText",
|
153
|
"stateData.$"
|
154
|
});
|
155
|
}
|