Project

General

Profile

Download (4.86 KB) Statistics
| Branch: | Tag: | Revision:
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.remote.dto.vaadin.CdmTaxonTableCollection;
29

    
30
/**
31
 *
32
 * This class is a Vaadin Component. It starts a long running session at the moment.
33
 * This might change in the future, but for now it beautifully works for this prototype.<p>
34
 * This class takes advantage of the dto and fills a container with data from the DB. Lazyloading or
35
 * Paging needs to be used!!!!
36
 * <p>
37
 * Further clarification is needed about the exact process when marking this component as dirty.
38
 * What will happen to the bound session? Why are changed Object saved without calling services explicitly.
39
 *
40
 *
41
 * @author a.oppermann
42
 *
43
 */
44

    
45
@Component
46
@Scope("request")
47
public class TaxonTableDTO extends Table{
48

    
49
	/**
50
	 * automatic generated ID
51
	 */
52
	@Autowired
53
	ITaxonService taxonService;
54
	@Autowired
55
	INameService nameService;
56
	@Autowired
57
	IDescriptionService descriptionService;
58
	@Autowired
59
	ITermService termService;
60

    
61
    @Autowired
62
    private HibernateTransactionManager transactionManager;
63

    
64
    @Autowired
65
    private DataSource dataSource;
66

    
67
    @Autowired
68
    private SessionFactory sessionFactory;
69

    
70
	private ConversationHolder conversationHolder;
71

    
72

    
73
	Logger logger = Logger.getLogger(TaxonTableDTO.class);
74

    
75
	private static final long serialVersionUID = -8449485694571526437L;
76

    
77
	@PostConstruct
78
	@SuppressWarnings("rawtypes")
79
	void PostConstruct(){
80
		setSizeFull();
81

    
82
//		conversationHolder = new ConversationHolder(dataSource, sessionFactory, transactionManager);
83
//		conversationHolder.bind();
84
		final BeanItemContainer<CdmTaxonTableCollection> redListContainer = new BeanItemContainer<CdmTaxonTableCollection>(CdmTaxonTableCollection.class);
85
		//TODO: Make use of paging
86
		Collection<Taxon> listTaxon = taxonService.list(Taxon.class, null, null, null, NODE_INIT_STRATEGY);
87

    
88
		for(Taxon taxonBase:listTaxon){
89

    
90
			Taxon taxon = taxonBase;
91
			List<PresenceAbsenceTermBase> termList = termService.list(PresenceAbsenceTermBase.class, null, null, null, DESCRIPTION_INIT_STRATEGY);
92
			List<DescriptionElementBase> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, null, null, null, null, DESCRIPTION_INIT_STRATEGY);
93
			CdmTaxonTableCollection tableCollection = new CdmTaxonTableCollection(taxon, listTaxonDescription, termList);
94
			redListContainer.addBean(tableCollection);
95
		}
96

    
97

    
98
		setContainerDataSource(redListContainer);
99
		setColumnReorderingAllowed(true);
100

    
101
		String[] columns = new String[]{"fullTitleCache", "rank", "UUID", "distributionStatus"};
102
		setVisibleColumns(columns);
103
		setColumnHeaders(new String[]{"Taxon", "Rang" , "UUID", "Deutschland"});
104
		setImmediate(true);
105
		setColumnCollapsingAllowed(true);
106
		setSelectable(true);
107
		setSizeFull();
108
		setPageLength(10);
109
	}
110

    
111
	public ConversationHolder getConversationHolder() {
112
		return conversationHolder;
113
	}
114

    
115

    
116
	private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[]{
117
    		"descriptions",
118
    		"descriptions.*",
119
    		"description.state",
120
    		"feature",
121
    		"feature.*",
122
    		"childNodes",
123
    		"childNodes.taxon",
124
    		"childNodes.taxon.name",
125
    		"taxonNodes",
126
    		"taxonNodes.*",
127
            "taxonNodes.taxon.*",
128
    		"taxon.*",
129
    		"taxon.descriptions",
130
    		"taxon.sec",
131
    		"taxon.name.*",
132
    		"taxon.synonymRelations",
133
    		"terms",
134
            "name.*",
135
            "name.rank.representations",
136
            "name.status.type.representations",
137
            "sources.$",
138
            "stateData.$"
139
    });
140

    
141
	protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
142
            "$",
143
            "elements.*",
144
            "elements.sources.citation.authorship.$",
145
            "elements.sources.nameUsedInSource.originalNameString",
146
            "elements.area.level",
147
            "elements.modifyingText",
148
            "elements.states.*",
149
            "elements.media",
150
            "elements.multilanguageText",
151
            "multilanguageText",
152
            "stateData.$"
153
    });
154
}
(6-6/6)