Revision a6584bc2
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.Collection; |
12 | 12 |
import java.util.HashMap; |
13 |
import java.util.HashSet; |
|
13 | 14 |
import java.util.List; |
14 | 15 |
import java.util.Map; |
15 | 16 |
import java.util.UUID; |
... | ... | |
18 | 19 |
|
19 | 20 |
import org.springframework.beans.factory.annotation.Autowired; |
20 | 21 |
import org.springframework.beans.factory.annotation.Qualifier; |
21 |
import org.springframework.stereotype.Component; |
|
22 |
import org.springframework.stereotype.Service; |
|
23 |
import org.springframework.transaction.TransactionStatus; |
|
24 |
import org.springframework.transaction.annotation.Transactional; |
|
22 | 25 |
|
23 | 26 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
27 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
28 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
24 | 29 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
25 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
|
30 |
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationDTO;
|
|
26 | 31 |
|
27 | 32 |
/** |
28 | 33 |
* @author a.kohlbecker |
29 | 34 |
* @since Mar 10, 2017 |
30 | 35 |
* |
31 | 36 |
*/ |
32 |
@Component("registrationServiceMock") |
|
37 |
@Service("registrationServiceMock") |
|
38 |
@Transactional |
|
33 | 39 |
public class RegistrationService { |
34 | 40 |
|
35 | 41 |
@Autowired |
... | ... | |
38 | 44 |
|
39 | 45 |
private Map<UUID, Registration> registrationsByUUID = new HashMap<>(); |
40 | 46 |
private Map<String, Registration> registrationsByRegID = new HashMap<>(); |
47 |
private Map<String, RegistrationDTO> registrationDTOsByRegID = new HashMap<>(); |
|
48 |
|
|
49 |
private Collection<CdmBase> cdmEntities = new HashSet<>(); |
|
41 | 50 |
|
42 | 51 |
public RegistrationService() { |
43 | 52 |
} |
44 | 53 |
|
54 |
|
|
55 |
int minTypeDesignationCount = 1; |
|
56 |
|
|
45 | 57 |
@PostConstruct |
46 | 58 |
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); |
|
59 |
TransactionStatus tx = repo.startTransaction(true); |
|
60 |
while(registrationsByUUID.size() < 20){ |
|
61 |
List<TaxonNameBase> names = repo.getNameService(). list(TaxonNameBase.class, 100, 0, null, null); |
|
62 |
for(TaxonNameBase name : names){ |
|
63 |
if(name.getRank().isLower(Rank.SUBFAMILY())){ |
|
64 |
if(name.getTypeDesignations().size() > minTypeDesignationCount - 1) { |
|
65 |
|
|
66 |
// name |
|
67 |
Registration nameReg = new Registration(); |
|
68 |
nameReg.setName(name); |
|
69 |
cdmEntities.add(name); |
|
70 |
put(nameReg, new RegistrationDTO(nameReg, null)); |
|
71 |
|
|
72 |
// typedesignation |
|
73 |
Registration typedesignationReg = new Registration(); |
|
74 |
typedesignationReg.addTypeDesignations(name.getTypeDesignations()); |
|
75 |
cdmEntities.addAll(name.getTypeDesignations()); |
|
76 |
put(typedesignationReg, new RegistrationDTO(typedesignationReg, name)); |
|
77 |
} |
|
54 | 78 |
} |
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 |
); |
|
79 |
} |
|
80 |
} |
|
81 |
repo.commitTransaction(tx); |
|
82 |
} |
|
65 | 83 |
|
84 |
/** |
|
85 |
* @param reg |
|
86 |
*/ |
|
87 |
private void put(Registration reg, RegistrationDTO dto) { |
|
88 |
registrationsByUUID.put(reg.getUuid(), reg); |
|
89 |
registrationsByRegID.put(reg.getSpecificIdentifier(), reg); |
|
90 |
registrationDTOsByRegID.put(reg.getSpecificIdentifier(), dto); |
|
66 | 91 |
} |
67 | 92 |
|
93 |
private void mergeBack(){ |
|
94 |
cdmEntities.forEach(e -> repo.getNameService().getSession().merge(e)); |
|
95 |
} |
|
68 | 96 |
|
69 | 97 |
/** |
70 | 98 |
* {@inheritDoc} |
... | ... | |
77 | 105 |
return registrationsByUUID.values(); |
78 | 106 |
} |
79 | 107 |
|
108 |
public Collection<RegistrationDTO> listDTOs() { |
|
109 |
return registrationDTOsByRegID.values(); |
|
110 |
} |
|
80 | 111 |
|
81 | 112 |
/** |
82 | 113 |
* @param registrationID |
Also available in: Unified diff
ref #6169 compact string representations for registrations