1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.vaadin.presenter;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
|
14
|
import com.vaadin.data.Container.Filter;
|
15
|
import com.vaadin.data.util.filter.Compare;
|
16
|
import com.vaadin.data.util.sqlcontainer.query.FreeformQuery;
|
17
|
import com.vaadin.data.util.sqlcontainer.query.OrderBy;
|
18
|
|
19
|
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
|
20
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
21
|
import eu.etaxonomy.cdm.vaadin.statement.CdmStatementDelegate;
|
22
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
23
|
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
|
24
|
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite.StatusComponentListener;
|
25
|
|
26
|
/**
|
27
|
* @author cmathew
|
28
|
* @date 10 Mar 2015
|
29
|
*
|
30
|
*/
|
31
|
public class StatusPresenter implements StatusComponentListener {
|
32
|
|
33
|
private static final String FROM_QUERY = "FROM TaxonNode tn inner join TaxonBase tb on tn.taxon_id=tb.id inner join TaxonNameBase tnb on tb.name_id=tnb.id inner join DefinedTermBase dtb on tnb.rank_id=dtb.id";
|
34
|
private static final String SELECT_QUERY="SELECT tb.id as taxon_id, tnb.titleCache as Name, tb.publish as Pb " + FROM_QUERY;
|
35
|
private static final String COUNT_QUERY = "SELECT count(*) " + FROM_QUERY;
|
36
|
|
37
|
private static final String CONTAINS_QUERY = "SELECT * FROM TaxonBase tb WHERE tb.id = ?";
|
38
|
|
39
|
private final IStatusComposite composite;
|
40
|
|
41
|
public StatusPresenter(IStatusComposite composite) {
|
42
|
this.composite = composite;
|
43
|
composite.setListener(this);
|
44
|
}
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener#load()
|
48
|
*/
|
49
|
@Override
|
50
|
public LeafNodeTaxonContainer loadTaxa(int classificationId) throws SQLException {
|
51
|
FreeformQuery query = new FreeformQuery("This query is not used", CdmSpringContextHelper.getConnectionPool(), "taxon_id");
|
52
|
CdmStatementDelegate cdmStatementDelegate = new CdmStatementDelegate(SELECT_QUERY, COUNT_QUERY, CONTAINS_QUERY);
|
53
|
query.setDelegate(cdmStatementDelegate);
|
54
|
|
55
|
Filter rankFilter = new Compare.Equal("dtb.titleCache","Species");
|
56
|
Filter classifcationFilter = new Compare.Equal("tn.classification_id",classificationId);
|
57
|
|
58
|
LeafNodeTaxonContainer container = new LeafNodeTaxonContainer(query);
|
59
|
container.addContainerFilter(rankFilter);
|
60
|
container.addContainerFilter(classifcationFilter);
|
61
|
return container;
|
62
|
}
|
63
|
|
64
|
|
65
|
/* (non-Javadoc)
|
66
|
* @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener#loadClassifications()
|
67
|
*/
|
68
|
@Override
|
69
|
public CdmSQLContainer loadClassifications() throws SQLException {
|
70
|
CdmSQLContainer container = CdmSQLContainer.newInstance("Classification");
|
71
|
container.addOrderBy(new OrderBy("titleCache", true));
|
72
|
return container;
|
73
|
}
|
74
|
|
75
|
}
|