Project

General

Profile

Download (5.21 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.agent.AgentBase;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceType;
28
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
29
import eu.etaxonomy.cdm.persistence.query.MatchMode;
30
import eu.etaxonomy.cdm.persistence.query.OrderHint;
31
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
32

    
33
/**
34
 * @author a.kohlbecker
35
 * @since Jun 7, 2018
36
 *
37
 */
38
@Component
39
public class CdmFilterablePagingProviderFactory {
40

    
41
    @Autowired
42
    @Qualifier("cdmRepository")
43
    private CdmRepository repo;
44

    
45
    public CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider() {
46
        return inReferencePagingProvider(null, false);
47
    }
48

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

    
68
        Set<ReferenceType> inRefTypes = subReferenceType.inReferenceContraints(subReferenceType);
69

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

    
79
        // using the ReferenceEllypsisFormatter initstrategy since using the ReferenceEllypsisCaptionGenerator should be default
80
        // for all views and UIs
81
        pagingProvider.setInitStrategy(ReferenceEllypsisFormatter.INIT_STRATEGY);
82

    
83
        return pagingProvider;
84
    }
85

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

    
96
        return pagingProvider;
97
    }
98

    
99
    public CdmFilterablePagingProvider<TaxonName, TaxonName> taxonNamesWithoutOrthophicIncorrect() {
100

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

    
111
    public CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> teamOrPersonPagingProvider() {
112
        return  new CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase>(repo.getAgentService(), TeamOrPersonBase.class, MatchMode.BEGINNING, OrderHint.ORDER_BY_TITLE_CACHE.asList());
113
    }
114

    
115
    public CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider() {
116
        return new CdmFilterablePagingProvider<AgentBase, Person>(repo.getAgentService(), Person.class, MatchMode.BEGINNING, OrderHint.ORDER_BY_TITLE_CACHE.asList());
117
    }
118

    
119
}
(3-3/13)