1
|
/**
|
2
|
* Copyright (C) 2016 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.controller;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
17
|
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
|
18
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
19
|
|
20
|
enum OrderHintPreset {
|
21
|
|
22
|
BY_ID_ASC(OrderHint.ORDER_BY_ID),
|
23
|
BY_ID_DESC(OrderHint.ORDER_BY_ID_DESC),
|
24
|
BY_ORDER_INDEX_DESC(OrderHint.BY_ORDER_INDEX_DESC),
|
25
|
BY_ORDER_INDEX_ASC(OrderHint.BY_ORDER_INDEX),
|
26
|
BY_TITLE_CACHE_ASC(OrderHint.ORDER_BY_TITLE_CACHE),
|
27
|
BY_TITLE_CACHE_DESC(OrderHint.ORDER_BY_TITLE_CACHE_DESC),
|
28
|
BY_NOMENCLATURAL_ORDER_ASC(OrderHint.NOMENCLATURAL_SORT_ORDER),
|
29
|
BY_NOMENCLATURAL_ORDER_DESC(OrderHint.NOMENCLATURAL_SORT_ORDER_DESC);
|
30
|
|
31
|
public static final Logger logger = Logger.getLogger(OrderHintPreset.class);
|
32
|
|
33
|
private final List<OrderHint> orderHints;
|
34
|
|
35
|
List<OrderHint> orderHints() {
|
36
|
return orderHints;
|
37
|
}
|
38
|
|
39
|
OrderHintPreset(OrderHint... orderHint) {
|
40
|
this.orderHints = Arrays.asList(orderHint);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Checks if the OrderHintPreset is suitable for the given <code>type</code>.
|
45
|
* In case this check fails the <code>BY_TITLE_CACHE_ASC</code> or
|
46
|
* <code>BY_TITLE_CACHE_DESC</code> is returned as fallback, depending on
|
47
|
* the sort order of the original sort order.
|
48
|
*
|
49
|
* @param type
|
50
|
*
|
51
|
* @return
|
52
|
*/
|
53
|
public OrderHintPreset checkSuitableFor(Class<? extends CdmBase> type) {
|
54
|
|
55
|
switch(this) {
|
56
|
case BY_ORDER_INDEX_ASC:
|
57
|
if(!OrderedTermVocabulary.class.isAssignableFrom(type)) {
|
58
|
logger.warn("BY_ORDER_INDEX_ASC not possible with " + type.getSimpleName() +" , falling back to BY_TITLE_CACHE_ASC");
|
59
|
return OrderHintPreset.BY_TITLE_CACHE_ASC;
|
60
|
}
|
61
|
break;
|
62
|
case BY_ORDER_INDEX_DESC:
|
63
|
if(!OrderedTermVocabulary.class.isAssignableFrom(type)) {
|
64
|
logger.warn( "BY_ORDER_INDEX_DESC not possible with " + type.getSimpleName() +" , falling back to BY_TITLE_CACHE_DESC");
|
65
|
return OrderHintPreset.BY_TITLE_CACHE_DESC;
|
66
|
}
|
67
|
break;
|
68
|
default:
|
69
|
// IGNORE
|
70
|
break;
|
71
|
}
|
72
|
|
73
|
return this;
|
74
|
}
|
75
|
}
|