1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.api.service;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Collection;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
import org.springframework.stereotype.Service;
|
21
|
import org.springframework.transaction.annotation.Transactional;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
24
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
25
|
import eu.etaxonomy.cdm.model.agent.Agent;
|
26
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
27
|
import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
|
28
|
import eu.etaxonomy.cdm.model.agent.Person;
|
29
|
import eu.etaxonomy.cdm.model.agent.Team;
|
30
|
import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;
|
31
|
|
32
|
|
33
|
|
34
|
/**
|
35
|
* @author a.mueller
|
36
|
*
|
37
|
*/
|
38
|
@Service
|
39
|
@Transactional
|
40
|
public class AgentServiceImpl extends IdentifiableServiceBase<Agent,IAgentDao> implements IAgentService {
|
41
|
@SuppressWarnings("unused")
|
42
|
private static final Logger logger = Logger.getLogger(AgentServiceImpl.class);
|
43
|
|
44
|
|
45
|
public List<Agent> findAgentsByTitle(String title) {
|
46
|
return super.findCdmObjectsByTitle(title);
|
47
|
}
|
48
|
|
49
|
public Agent getAgentByUuid(UUID uuid) {
|
50
|
return dao.findByUuid(uuid);
|
51
|
}
|
52
|
|
53
|
public UUID saveAgent(Agent agent) {
|
54
|
return super.saveCdmObject(agent);
|
55
|
}
|
56
|
|
57
|
@Transactional(readOnly = false)
|
58
|
public Map<UUID, Agent> saveAgentAll(Collection<? extends Agent> agentCollection){
|
59
|
return saveCdmObjectAll(agentCollection);
|
60
|
}
|
61
|
|
62
|
|
63
|
public List<Agent> getAllAgents(int limit, int start){
|
64
|
return dao.list(limit, start);
|
65
|
}
|
66
|
|
67
|
public List<Institution> searchInstitutionByCode(String code) {
|
68
|
return dao.getInstitutionByCode(code);
|
69
|
}
|
70
|
|
71
|
public void generateTitleCache() {
|
72
|
// TODO Auto-generated method stub
|
73
|
|
74
|
}
|
75
|
|
76
|
@Autowired
|
77
|
protected void setDao(IAgentDao dao) {
|
78
|
assert dao != null;
|
79
|
this.dao = dao;
|
80
|
}
|
81
|
|
82
|
public Pager<InstitutionalMembership> getInstitutionalMemberships(Person person, Integer pageSize, Integer pageNumber) {
|
83
|
Integer numberOfResults = dao.countInstitutionalMemberships(person);
|
84
|
|
85
|
List<InstitutionalMembership> results = new ArrayList<InstitutionalMembership>();
|
86
|
if(numberOfResults > 0) { // no point checking again
|
87
|
results = dao.getInstitutionalMemberships(person, pageSize, pageNumber);
|
88
|
}
|
89
|
|
90
|
return new DefaultPagerImpl<InstitutionalMembership>(pageNumber, numberOfResults, pageSize, results);
|
91
|
}
|
92
|
|
93
|
public Pager<Person> getMembers(Team team, Integer pageSize, Integer pageNumber) {
|
94
|
Integer numberOfResults = dao.countMembers(team);
|
95
|
|
96
|
List<Person> results = new ArrayList<Person>();
|
97
|
if(numberOfResults > 0) { // no point checking again
|
98
|
results = dao.getMembers(team, pageSize, pageNumber);
|
99
|
}
|
100
|
|
101
|
return new DefaultPagerImpl<Person>(pageNumber, numberOfResults, pageSize, results);
|
102
|
}
|
103
|
|
104
|
|
105
|
}
|