Project

General

Profile

Download (4.53 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.service;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.Set;
15

    
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Qualifier;
18
import org.springframework.stereotype.Component;
19

    
20
import eu.etaxonomy.cdm.api.application.CdmRepository;
21
import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter;
22
import eu.etaxonomy.cdm.model.name.TaxonName;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.model.reference.ReferenceType;
25
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
26
import eu.etaxonomy.cdm.persistence.query.MatchMode;
27
import eu.etaxonomy.cdm.persistence.query.OrderHint;
28
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
29

    
30
/**
31
 * @author a.kohlbecker
32
 * @since Jun 7, 2018
33
 *
34
 */
35
@Component
36
public class CdmFilterablePagingProviderFactory {
37

    
38
    @Autowired
39
    @Qualifier("cdmRepository")
40
    private CdmRepository repo;
41

    
42
    public CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider() {
43
        return inReferencePagingProvider(null, false);
44
    }
45

    
46
    /**
47
     *
48
     * @param subReferenceType
49
     *            the type of the reference for which to the paging provider is
50
     *            to be created
51
     * @param includeUnspecificTypes
52
     *            Whether to include references with the types
53
     *            {@link ReferenceType.Generic Generic} and {@code null},
54
     * @return
55
     */
56
    public CdmFilterablePagingProvider<Reference, Reference> inReferencePagingProvider(ReferenceType subReferenceType,
57
            boolean includeUnspecificTypes) {
58
        List<OrderHint> referenceOrderHints = new ArrayList<OrderHint>();
59
        referenceOrderHints.add(OrderHint.ORDER_BY_TITLE_CACHE);
60
        referenceOrderHints.add(new OrderHint("issn", SortOrder.ASCENDING));
61
        referenceOrderHints.add(new OrderHint("isbn", SortOrder.ASCENDING));
62
        CdmFilterablePagingProvider<Reference, Reference> pagingProvider = new CdmFilterablePagingProvider<Reference, Reference>(
63
                repo.getReferenceService(), MatchMode.ANYWHERE, referenceOrderHints);
64

    
65
        Set<ReferenceType> inRefTypes = subReferenceType.inReferenceContraints(subReferenceType);
66

    
67
        if (!inRefTypes.isEmpty()) {
68
            if (includeUnspecificTypes) {
69
                inRefTypes.add(ReferenceType.Generic);
70
                inRefTypes.add(null);
71
            }
72
            pagingProvider.addRestriction(new Restriction<ReferenceType>("type", null,
73
                    inRefTypes.toArray(new ReferenceType[inRefTypes.size()])));
74
        }
75

    
76
        // using the ReferenceEllypsisFormatter initstrategy since using the ReferenceEllypsisCaptionGenerator should be default
77
        // for all views and UIs
78
        pagingProvider.setInitStrategy(ReferenceEllypsisFormatter.INIT_STRATEGY);
79

    
80
        return pagingProvider;
81
    }
82

    
83
    public TypifiedEntityFilterablePagingProvider<Reference> referenceEntityReferencePagingProvider(
84
            ReferenceEllypsisFormatter labelProvider, List<String> initStrategy) {
85
        List<OrderHint> referenceOrderHints = new ArrayList<OrderHint>();
86
        referenceOrderHints.add(OrderHint.ORDER_BY_TITLE_CACHE);
87
        referenceOrderHints.add(new OrderHint("issn", SortOrder.ASCENDING));
88
        referenceOrderHints.add(new OrderHint("isbn", SortOrder.ASCENDING));
89
        TypifiedEntityFilterablePagingProvider<Reference> pagingProvider = new TypifiedEntityFilterablePagingProvider<Reference>(
90
                repo.getReferenceService(), MatchMode.BEGINNING, referenceOrderHints, labelProvider);
91
        pagingProvider.setInitStrategy(initStrategy);
92

    
93
        return pagingProvider;
94
    }
95

    
96
    public CdmFilterablePagingProvider<TaxonName, TaxonName> taxonNamesWithoutOrthophicIncorrect() {
97

    
98
        CdmFilterablePagingProvider<TaxonName, TaxonName> pagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(
99
                repo.getNameService());
100
        pagingProvider.setInitStrategy(
101
                Arrays.asList("registrations", "nomenclaturalReference", "nomenclaturalReference.inReference"));
102
        // pagingProvider.addRestriction(new
103
        // Restriction<>("relationsFromThisName.type", Operator.AND_NOT, null,
104
        // NameRelationshipType.ORTHOGRAPHIC_VARIANT()));
105
        return pagingProvider;
106
    }
107

    
108
}
(3-3/13)