1
|
package eu.etaxonomy.cdm.vaadin.presenter.dbstatus;
|
2
|
|
3
|
import java.sql.SQLException;
|
4
|
import java.util.ArrayList;
|
5
|
import java.util.Arrays;
|
6
|
import java.util.HashMap;
|
7
|
import java.util.HashSet;
|
8
|
import java.util.List;
|
9
|
import java.util.Set;
|
10
|
import java.util.UUID;
|
11
|
|
12
|
import com.vaadin.data.util.BeanItemContainer;
|
13
|
import com.vaadin.server.VaadinSession;
|
14
|
import com.vaadin.ui.ComboBox;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
17
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
18
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
19
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
20
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
21
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
24
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
25
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
26
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
27
|
import eu.etaxonomy.cdm.model.description.Feature;
|
28
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
30
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
31
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
32
|
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
|
33
|
import eu.etaxonomy.cdm.vaadin.model.CdmTaxonTableCollection;
|
34
|
import eu.etaxonomy.cdm.vaadin.model.DbTableDTO;
|
35
|
import eu.etaxonomy.cdm.vaadin.model.DbTableDTOS;
|
36
|
import eu.etaxonomy.cdm.vaadin.model.LazyLoadedContainer;
|
37
|
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
|
38
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
39
|
import eu.etaxonomy.cdm.vaadin.view.dbstatus.DistributionTableView;
|
40
|
import eu.etaxonomy.cdm.vaadin.view.dbstatus.IDistributionTableComponent;
|
41
|
|
42
|
|
43
|
public class DistributionTablePresenter implements IDistributionTableComponent.DistributionTableComponentListener{
|
44
|
|
45
|
|
46
|
private final IClassificationService classificationService;
|
47
|
private final IVocabularyService vocabularyService;
|
48
|
private final IDescriptionService descriptionService;
|
49
|
private final ITaxonNodeService taxonNodeService;
|
50
|
private final ITermService termService;
|
51
|
private final DistributionTableView view;
|
52
|
private ITaxonService taxonService;
|
53
|
|
54
|
public DistributionTablePresenter(DistributionTableView dtv) throws SQLException{
|
55
|
this.view = dtv;
|
56
|
view.addListener(this);
|
57
|
taxonService = (ITaxonService)CdmSpringContextHelper.newInstance().getBean("taxonServiceImpl");
|
58
|
classificationService = (IClassificationService)CdmSpringContextHelper.newInstance().getBean("classificationServiceImpl");
|
59
|
taxonNodeService = (ITaxonNodeService)CdmSpringContextHelper.newInstance().getBean("taxonNodeServiceImpl");
|
60
|
vocabularyService = (IVocabularyService)CdmSpringContextHelper.newInstance().getBean("vocabularyServiceImpl");
|
61
|
descriptionService = (IDescriptionService)CdmSpringContextHelper.newInstance().getBean("descriptionServiceImpl");
|
62
|
termService = (ITermService)CdmSpringContextHelper.newInstance().getBean("termServiceImpl");
|
63
|
view.dataBinding();
|
64
|
}
|
65
|
|
66
|
|
67
|
public ComboBox updateDistributionField(DescriptionElementBase deb,
|
68
|
Distribution db,
|
69
|
BeanItemContainer<PresenceAbsenceTerm> termContainer, ComboBox box,
|
70
|
Taxon taxon) {
|
71
|
// TODO Auto-generated method stub
|
72
|
return null;
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public Set<DefinedTermBase> getChosenTerms() {
|
77
|
VaadinSession session = VaadinSession.getCurrent();
|
78
|
UUID termUUID = (UUID) session.getAttribute("selectedTerm");
|
79
|
TermVocabulary<DefinedTermBase> term = vocabularyService.load(termUUID);
|
80
|
term = CdmBase.deproxy(term, TermVocabulary.class);
|
81
|
return term.getTerms();
|
82
|
}
|
83
|
|
84
|
|
85
|
public List<String> getTermList() {
|
86
|
VaadinSession session = VaadinSession.getCurrent();
|
87
|
UUID termUUID = (UUID) session.getAttribute("selectedTerm");
|
88
|
TermVocabulary<DefinedTermBase> term = vocabularyService.load(termUUID);
|
89
|
term = CdmBase.deproxy(term, TermVocabulary.class);
|
90
|
Set<DefinedTermBase> terms = term.getTerms();
|
91
|
List<String> list = new ArrayList<String>();
|
92
|
for(DefinedTermBase dtb: terms){
|
93
|
list.add(dtb.getTitleCache());
|
94
|
}
|
95
|
return list;
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon) {
|
100
|
Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
|
101
|
List<DescriptionElementBase> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
102
|
HashMap<DescriptionElementBase, Distribution> map = null;
|
103
|
for(DescriptionElementBase deb : listTaxonDescription){
|
104
|
if(deb instanceof Distribution){
|
105
|
Distribution db = (Distribution)deb;
|
106
|
String titleCache = dt.getTitleCache();
|
107
|
if(db.getArea().getTitleCache().equalsIgnoreCase(titleCache)){
|
108
|
map = new HashMap<DescriptionElementBase, Distribution>();
|
109
|
map.put(deb, db);
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
return map;
|
114
|
}
|
115
|
@Override
|
116
|
public List<DescriptionElementBase> listDescriptionElementsForTaxon(Taxon taxon, Set<Feature> setFeature){
|
117
|
return descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public List<Distribution> getDistribution(Taxon taxon) {
|
122
|
Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
|
123
|
List<Distribution> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
124
|
return listTaxonDescription;
|
125
|
|
126
|
}
|
127
|
|
128
|
@Override
|
129
|
public List<TaxonNode> getAllNodes(int start, int end){
|
130
|
Classification classification = getChosenClassification();
|
131
|
List<TaxonNode> nodesForClassification = taxonNodeService.listAllNodesForClassification(classification, start, end);
|
132
|
return nodesForClassification;
|
133
|
}
|
134
|
|
135
|
|
136
|
@Override
|
137
|
public Classification getChosenClassification() {
|
138
|
VaadinSession session = VaadinSession.getCurrent();
|
139
|
UUID classificationUUID = (UUID) session.getAttribute("classificationUUID");
|
140
|
Classification classification = classificationService.load(classificationUUID);
|
141
|
return classification;
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public int getSizeOfClassification(){
|
146
|
Classification classification = getChosenClassification();
|
147
|
return taxonNodeService.countAllNodesForClassification(classification);
|
148
|
}
|
149
|
|
150
|
@Override
|
151
|
public DbTableDTOS getDataList(int start, int end){
|
152
|
List<TaxonNode> nodes = getAllNodes(start, end);
|
153
|
DbTableDTOS items = new DbTableDTOS();
|
154
|
for(TaxonNode tn: nodes){
|
155
|
Taxon taxon = tn.getTaxon();
|
156
|
DbTableDTO dbTableDTO = new DbTableDTO(taxon);
|
157
|
|
158
|
Set<DefinedTermBase> terms = getChosenTerms();
|
159
|
List<Distribution> distribution = getDistribution(taxon);
|
160
|
for(DefinedTermBase dt: terms){
|
161
|
for(Distribution db : distribution){
|
162
|
if(dt.getTitleCache().equalsIgnoreCase(db.getArea().getTitleCache())){
|
163
|
// DistributionDTO distributionDTO = new DistributionDTO(db.getStatus().getTitleCache());
|
164
|
// dbTableDTO.setdDTO(distributionDTO);
|
165
|
}
|
166
|
|
167
|
}
|
168
|
}
|
169
|
items.add(dbTableDTO);
|
170
|
}
|
171
|
return items;
|
172
|
}
|
173
|
|
174
|
@Override
|
175
|
public CdmSQLContainer getSQLContainer() throws SQLException{
|
176
|
Classification classification = getChosenClassification();
|
177
|
int classificationId = classification.getId();
|
178
|
List<String> termList = getTermList();
|
179
|
CdmSQLContainer container = new CdmSQLContainer(new CdmQueryFactory().generateTaxonDistributionQuery("id", termList, classificationId));
|
180
|
return container;
|
181
|
}
|
182
|
|
183
|
@Override
|
184
|
public LazyLoadedContainer getLazyLoadedContainer(){
|
185
|
LazyLoadedContainer lz = new LazyLoadedContainer(CdmTaxonTableCollection.class);
|
186
|
lz.addListener(this);
|
187
|
return lz;
|
188
|
|
189
|
}
|
190
|
|
191
|
|
192
|
@Override
|
193
|
public List<PresenceAbsenceTerm> getPresenceAbsenceTerms() {
|
194
|
//TODO Better to use TermType instead of class to get the list
|
195
|
return termService.list(PresenceAbsenceTerm.class, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
196
|
}
|
197
|
|
198
|
protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
199
|
"$",
|
200
|
"elements.*",
|
201
|
"elements.sources.citation.authorship.$",
|
202
|
"elements.sources.nameUsedInSource.originalNameString",
|
203
|
"elements.area.level",
|
204
|
"elements.modifyingText",
|
205
|
"elements.states.*",
|
206
|
"elements.media",
|
207
|
"elements.multilanguageText",
|
208
|
"multilanguageText",
|
209
|
"stateData.$"
|
210
|
});
|
211
|
|
212
|
|
213
|
@Override
|
214
|
public IClassificationService getClassificationService() {
|
215
|
return classificationService;
|
216
|
}
|
217
|
|
218
|
|
219
|
@Override
|
220
|
public IVocabularyService getVocabularyService() {
|
221
|
return vocabularyService;
|
222
|
}
|
223
|
|
224
|
|
225
|
@Override
|
226
|
public IDescriptionService getDescriptionService() {
|
227
|
return descriptionService;
|
228
|
}
|
229
|
|
230
|
|
231
|
@Override
|
232
|
public ITaxonNodeService getTaxonNodeService() {
|
233
|
return taxonNodeService;
|
234
|
}
|
235
|
|
236
|
|
237
|
@Override
|
238
|
public ITermService getTermService() {
|
239
|
return termService;
|
240
|
}
|
241
|
|
242
|
@Override
|
243
|
public LazyLoadedContainer getTableContainer() {
|
244
|
// TODO Auto-generated method stub
|
245
|
return null;
|
246
|
}
|
247
|
|
248
|
|
249
|
|
250
|
@Override
|
251
|
public ITaxonService getTaxonService() {
|
252
|
return taxonService;
|
253
|
}
|
254
|
|
255
|
|
256
|
}
|