Project

General

Profile

« Previous | Next » 

Revision b5f17980

Added by Patrick Plitzner over 7 years ago

ref #5458 Fix exception for non-unique column ids

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
156 156
        return namedAreas;
157 157
	}
158 158

  
159
    public List<String> getNamedAreasLabels(){
160
        Set<NamedArea> selectedAreas = getNamedAreas();
161
    	List<String> namedAreaTitles = new ArrayList<>();
162
    	for (NamedArea namedArea : selectedAreas) {
163
    		String title = null;
164
    	    Representation representation = namedArea.getRepresentation(Language.DEFAULT());
165
    	    if(representation!=null){
166
    	    	if(DistributionEditorUtil.isAbbreviatedLabels()){
167
    	    		title = representation.getAbbreviatedLabel();
168
    	    	}
169
    	    	else{
170
    	    		title = representation.getLabel();
171
    	    	}
172
    	    }
173
    	    if(title==null){
174
    	    	title = namedArea.getTitleCache();
175
    	    }
176
    	    namedAreaTitles.add(title);
177
        }
178
    	return namedAreaTitles;
179
    }
180

  
181 159
	private Set<NamedArea> getTermSet(){
182 160
	    VaadinSession session = VaadinSession.getCurrent();
183 161
	    UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
10 10
package eu.etaxonomy.cdm.vaadin.util;
11 11

  
12 12
import java.util.Collection;
13
import java.util.HashMap;
13 14
import java.util.Iterator;
14 15
import java.util.List;
16
import java.util.Map;
15 17
import java.util.regex.Matcher;
16 18
import java.util.regex.Pattern;
17 19

  
......
33 35
public class CdmQueryFactory {
34 36

  
35 37

  
36
	public static final String RANK_COLUMN = "Rank";
38
	public static final String DTYPE_COLUMN = "DTYPE";
39
	public static final String ID_COLUMN = "id";
40
	public static final String UUID_COLUMN = "uuid";
41
	public static final String CLASSIFICATION_COLUMN = "classification";
42
	public static final String RANK_COLUMN = "Rang";
37 43
	public static final String TAXON_COLUMN = "Taxon";
38 44

  
39 45
    public static final String ID = "id";
......
105 111
        String ORDER_BY = " ORDER BY tb.titleCache ";
106 112

  
107 113
        String SELECT_QUERY= "SELECT "
108
                + "tb.DTYPE, "
109
                + "tb.id, "
110
                + "tb.uuid, "
111
                + "tn.classification_id, "+
114
                + "tb.DTYPE AS "+DTYPE_COLUMN+", "
115
                + "tb.id AS "+ID_COLUMN+", "
116
                + "tb.uuid AS "+UUID_COLUMN+", "
117
                + "tn.classification_id AS "+CLASSIFICATION_COLUMN+", "+
112 118
        		"tb.titleCache AS "+TAXON_COLUMN+", " +
113 119
        		"rank.titleCache AS "+RANK_COLUMN+", ";
114 120

  
121
        Map<String, Integer> labels = new HashMap<>();
115 122
        for(NamedArea namedArea : namedAreas){
116 123
            String label = null;
124
            String fullLabel = null;
125
            String abbreviatedLabel = null;
117 126
            Representation representation = namedArea.getRepresentation(Language.DEFAULT());
118 127
            if(representation!=null){
128
            	fullLabel = representation.getLabel();
129
				abbreviatedLabel = representation.getAbbreviatedLabel();
119 130
				if(DistributionEditorUtil.isAbbreviatedLabels()){
120
            		label = representation.getAbbreviatedLabel();
131
            		label = abbreviatedLabel;
121 132
            	}
122 133
            	else{
123
            		label = representation.getLabel();
134
            		label = fullLabel;
124 135
            	}
125 136
            }
137
            //fallback
126 138
            if(label==null){
127 139
            	label = namedArea.getTitleCache();
128 140
            }
129
            SELECT_QUERY += "MAX( IF(area.titleCache = '"+ namedArea.getTitleCache() +"', statusTerm.titleCache, NULL) ) as '"+ label +"'," ;
141

  
142
            //check if label already exists
143
            Integer count = labels.get(label);
144
            if(count!=null){
145
            	//combine label and abbreviated and check again
146
            	if(abbreviatedLabel!=null && fullLabel!= null){
147
            		label = abbreviatedLabel+"-"+fullLabel;
148
            	}
149
            }
150
            count = labels.get(label);
151
            if(count==null){
152
            	labels.put(label, 1);
153
            }
154
            else{
155
            	labels.put(label, count+1);
156
            	label += "("+count+")";
157
            }
158
            SELECT_QUERY += "MAX( IF(area.uuid = '"+ namedArea.getUuid() +"', statusTerm.titleCache, NULL) ) as '"+ label +"'," ;
130 159
        }
131 160
        SELECT_QUERY = StringUtils.stripEnd(SELECT_QUERY, ",")+" ";
132 161
        SELECT_QUERY= SELECT_QUERY + FROM_QUERY + GROUP_BY + ORDER_BY;
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
53 53

  
54 54
	private DistributionTablePresenter listener;
55 55

  
56
	private List<String> columnList;
57
	private ArrayList<String> headerList;
58 56
    private CdmSQLContainer container;
59 57

  
60 58
	/**
......
187 185

  
188 186
		table.setContainerDataSource(container);
189 187

  
190
		columnList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,CdmQueryFactory.RANK_COLUMN}));
191
		List<String> namedAreas = listener.getNamedAreasLabels();
192
		columnList.addAll(namedAreas);
193
		table.setVisibleColumns(columnList.toArray());
188
		List<String> columnHeaders = new ArrayList<>(Arrays.asList(table.getColumnHeaders()));
189
		columnHeaders.remove(CdmQueryFactory.DTYPE_COLUMN);
190
		columnHeaders.remove(CdmQueryFactory.ID_COLUMN);
191
		columnHeaders.remove(CdmQueryFactory.UUID_COLUMN);
192
		columnHeaders.remove(CdmQueryFactory.CLASSIFICATION_COLUMN);
194 193

  
195
		headerList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,"Rang"}));
196
		headerList.addAll(listener.getNamedAreasLabels());
197
		String[] string = new String[headerList.size()];
198
		table.setColumnHeaders(headerList.toArray(string));
194
		List<String> columnList = new ArrayList<String>(columnHeaders);
195
		
196
		String[] string = new String[columnList.size()];
199 197

  
198
		table.setVisibleColumns(columnList.toArray());
199
		table.setColumnHeaders(columnList.toArray(string));
200 200
		table.setColumnFooter(CdmQueryFactory.TAXON_COLUMN, "Total amount of Taxa displayed: " + container.size());
201 201

  
202 202

  

Also available in: Unified diff