Project

General

Profile

Download (5.2 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

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

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

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

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

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

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

    
67
        List<ReferenceType> inRefTypes = ReferenceType.inReferenceContraints(subReferenceType);
68

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

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

    
82
        return pagingProvider;
83
    }
84

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

    
95
        return pagingProvider;
96
    }
97

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

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

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

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

    
118
}
(4-4/13)