Project

General

Profile

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

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.Optional;
15

    
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Service;
18
import org.springframework.transaction.annotation.Transactional;
19

    
20
import eu.etaxonomy.cdm.api.service.pager.Pager;
21
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
22
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
23
import eu.etaxonomy.cdm.model.common.User;
24
import eu.etaxonomy.cdm.model.name.Registration;
25
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
28
import eu.etaxonomy.cdm.persistence.dao.name.IRegistrationDao;
29
import eu.etaxonomy.cdm.persistence.query.MatchMode;
30
import eu.etaxonomy.cdm.persistence.query.OrderHint;
31

    
32
/**
33
 * @author a.kohlbecker
34
 * @since May 2, 2017
35
 *
36
 */
37
@Service
38
@Transactional(readOnly = true)
39
public class RegistrationServiceImpl extends AnnotatableServiceBase<Registration, IRegistrationDao> implements IRegistrationService {
40

    
41
    /**
42
     * {@inheritDoc}
43
     */
44
    @Autowired
45
    @Override
46
    protected void setDao(IRegistrationDao dao) {
47
        this.dao = dao;
48
    }
49

    
50
    /**
51
     * {@inheritDoc}
52
     */
53
    @Override
54
    public Pager<Registration> page(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus,
55
            Integer pageSize, Integer pageIndex, List<String> propertyPaths) {
56

    
57
        long numberOfResults = dao.count(reference, includedStatus);
58

    
59
        List<Registration> results = new ArrayList<>();
60
        Integer [] limitStart = AbstractPagerImpl.limitStartforRange(numberOfResults, pageIndex, pageSize);
61
        if(limitStart != null) {
62
            results = dao.list(reference, includedStatus, limitStart[0], limitStart[1], propertyPaths);
63
        }
64

    
65
        return new DefaultPagerImpl<>(pageIndex, numberOfResults, pageSize, results);
66
    }
67

    
68
    /**
69
     * {@inheritDoc}
70
     */
71
    @Override
72
    public Pager<Registration> page(User submitter, Collection<RegistrationStatus> includedStatus,
73
            String identifierFilterPattern, String taxonNameFilterPattern,
74
            Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths) {
75

    
76
        List<Restriction<? extends Object>> restrictions = new ArrayList<>();
77

    
78
        if(submitter != null){
79
            restrictions.add(new Restriction<>("submitter", MatchMode.EXACT, submitter));
80
        }
81
        if(includedStatus != null && !includedStatus.isEmpty()){
82
            restrictions.add(new Restriction<>("status", MatchMode.EXACT, includedStatus.toArray(new RegistrationStatus[includedStatus.size()])));
83
        }
84
        if(identifierFilterPattern != null){
85
            restrictions.add(new Restriction<>("identifier", MatchMode.LIKE, identifierFilterPattern));
86
        }
87
        if(taxonNameFilterPattern != null){
88
            restrictions.add(new Restriction<>("name.titleCache", MatchMode.LIKE, taxonNameFilterPattern));
89
        }
90

    
91

    
92
        long numberOfResults = dao.count(Registration.class, restrictions);
93

    
94
        List<Registration> results = new ArrayList<>();
95
        Integer [] limitStart = AbstractPagerImpl.limitStartforRange(numberOfResults, pageIndex, pageSize);
96
        if(limitStart != null) {
97
            results = dao.list(Registration.class, restrictions, limitStart[0], limitStart[1], orderHints, propertyPaths);
98
        }
99

    
100
        return new DefaultPagerImpl<>(pageIndex, numberOfResults, pageSize, results);
101
    }
102

    
103

    
104
}
(88-88/105)