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.mock;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import javax.annotation.PostConstruct;
|
18
|
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
import org.springframework.beans.factory.annotation.Qualifier;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
25
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
26
|
|
27
|
/**
|
28
|
* @author a.kohlbecker
|
29
|
* @since Mar 10, 2017
|
30
|
*
|
31
|
*/
|
32
|
@Component("registrationServiceMock")
|
33
|
public class RegistrationService {
|
34
|
|
35
|
@Autowired
|
36
|
@Qualifier("cdmRepository")
|
37
|
private CdmRepository repo;
|
38
|
|
39
|
private Map<UUID, Registration> registrationsByUUID = new HashMap<>();
|
40
|
private Map<String, Registration> registrationsByRegID = new HashMap<>();
|
41
|
|
42
|
public RegistrationService() {
|
43
|
}
|
44
|
|
45
|
@PostConstruct
|
46
|
protected void init(){
|
47
|
List<TaxonNameBase> names = repo.getNameService().list(TaxonNameBase.class, 20, 0, null, null);
|
48
|
names.forEach(
|
49
|
name -> {
|
50
|
Registration reg = new Registration();
|
51
|
reg.setName(name);
|
52
|
registrationsByUUID.put(reg.getUuid(), reg);
|
53
|
registrationsByRegID.put(reg.getSpecificIdentifier(), reg);
|
54
|
}
|
55
|
);
|
56
|
List<TypeDesignationBase> tds = repo.getNameService().getAllTypeDesignations(20, 0);
|
57
|
tds.forEach(
|
58
|
type -> {
|
59
|
Registration reg = new Registration();
|
60
|
reg.addTypeDesignationBase(type);
|
61
|
registrationsByUUID.put(reg.getUuid(), reg);
|
62
|
registrationsByRegID.put(reg.getSpecificIdentifier(), reg);
|
63
|
}
|
64
|
);
|
65
|
|
66
|
}
|
67
|
|
68
|
|
69
|
/**
|
70
|
* {@inheritDoc}
|
71
|
*/
|
72
|
public Registration load(UUID uuid) {
|
73
|
return registrationsByUUID.get(uuid);
|
74
|
}
|
75
|
|
76
|
public Collection<Registration> list(){
|
77
|
return registrationsByUUID.values();
|
78
|
}
|
79
|
|
80
|
|
81
|
/**
|
82
|
* @param registrationID
|
83
|
* @return
|
84
|
*/
|
85
|
public Registration loadByRegistrationID(Integer registrationID) {
|
86
|
return registrationsByRegID.get(registrationID.toString());
|
87
|
}
|
88
|
|
89
|
|
90
|
}
|