Revision fe8fe1e2
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java | ||
---|---|---|
16 | 16 |
import java.util.Map; |
17 | 17 |
import java.util.UUID; |
18 | 18 |
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.joda.time.DateTime; |
|
19 | 21 |
import org.springframework.beans.factory.annotation.Autowired; |
20 | 22 |
import org.springframework.beans.factory.annotation.Qualifier; |
21 | 23 |
import org.springframework.stereotype.Service; |
... | ... | |
25 | 27 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
26 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
27 | 29 |
import eu.etaxonomy.cdm.model.name.Rank; |
30 |
import eu.etaxonomy.cdm.model.name.Registration; |
|
31 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
|
28 | 32 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
29 | 33 |
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet; |
30 | 34 |
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO; |
... | ... | |
41 | 45 |
|
42 | 46 |
private static final int SIZE = 50; // FIXME test performance with 50 !!!!! |
43 | 47 |
|
48 |
private static final Logger logger = Logger.getLogger(RegistrationService.class); |
|
49 |
|
|
44 | 50 |
@Autowired |
45 | 51 |
@Qualifier("cdmRepository") |
46 | 52 |
private CdmRepository repo; |
... | ... | |
53 | 59 |
|
54 | 60 |
private Collection<CdmBase> cdmEntities = new HashSet<>(); |
55 | 61 |
|
62 |
int autoincrementId = 100000; |
|
63 |
|
|
56 | 64 |
public RegistrationService() { |
57 | 65 |
} |
58 | 66 |
|
... | ... | |
60 | 68 |
int minTypeDesignationCount = 1; |
61 | 69 |
|
62 | 70 |
protected void init(){ |
71 |
if(isCleanSweep()){ |
|
72 |
autoincrementId = 100000; |
|
73 |
registrationsByUUID = new HashMap<>(); |
|
74 |
registrationsByRegID = new HashMap<>(); |
|
75 |
registrationDTOsById = new HashMap<>(); |
|
76 |
registrationDTOsByIdentifier = new HashMap<>(); |
|
77 |
registrationDTOsByCitationId = new HashMap<>(); |
|
78 |
} |
|
63 | 79 |
if(registrationsByUUID.size() == 0){ |
64 | 80 |
TransactionStatus tx = repo.startTransaction(true); |
65 | 81 |
int pageIndex = 0; |
... | ... | |
69 | 85 |
break; |
70 | 86 |
} |
71 | 87 |
for(TaxonNameBase name : names){ |
72 |
if(name != null && name.getRank() != null && name.getRank().isLower(Rank.SUBFAMILY())){ |
|
88 |
if(name != null && name.getRank() != null && name.getRank().isLower(Rank.SUBFAMILY()) && name.getNomenclaturalReference() != null){
|
|
73 | 89 |
if(name.getTypeDesignations().size() > minTypeDesignationCount - 1) { |
74 | 90 |
|
75 | 91 |
// name |
76 |
Registration nameReg = new Registration(); |
|
77 |
nameReg.setName(name); |
|
92 |
logger.debug("creating Registration for " + name.getTitleCache()); |
|
93 |
Registration reg = newMockRegistration(); |
|
94 |
reg.setName(name); |
|
78 | 95 |
cdmEntities.add(name); |
79 |
put(new RegistrationDTO(nameReg)); |
|
80 | 96 |
|
81 | 97 |
// typedesignation |
82 |
Registration typedesignationReg = new Registration(); |
|
83 |
typedesignationReg.addTypeDesignations(name.getTypeDesignations()); |
|
98 |
reg.setTypeDesignations(name.getTypeDesignations()); |
|
84 | 99 |
cdmEntities.addAll(name.getTypeDesignations()); |
85 |
put(new RegistrationDTO(typedesignationReg)); |
|
100 |
|
|
101 |
put(new RegistrationDTO(reg)); |
|
102 |
logger.debug("\t\t\tdone"); |
|
86 | 103 |
} |
87 | 104 |
} |
88 | 105 |
} |
... | ... | |
91 | 108 |
} |
92 | 109 |
} |
93 | 110 |
|
111 |
/** |
|
112 |
* @return |
|
113 |
*/ |
|
114 |
private Registration newMockRegistration() { |
|
115 |
Registration reg = Registration.NewInstance(); |
|
116 |
reg.setId(autoincrementId); |
|
117 |
reg.setSpecificIdentifier(String.valueOf(autoincrementId)); |
|
118 |
reg.setIdentifier("http://phycobank/" + reg.getSpecificIdentifier()); |
|
119 |
autoincrementId++; |
|
120 |
reg.setStatus(RegistrationStatus.values()[(int) (Math.random() * RegistrationStatus.values().length)]); |
|
121 |
reg.setRegistrationDate(DateTime.now()); |
|
122 |
return reg; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* @return |
|
127 |
*/ |
|
128 |
private boolean isCleanSweep() { |
|
129 |
|
|
130 |
return false; |
|
131 |
} |
|
132 |
|
|
94 | 133 |
/** |
95 | 134 |
* @param reg |
96 | 135 |
*/ |
97 | 136 |
private void put(RegistrationDTO dto) { |
137 |
logger.debug("putting DTO " + dto.getSummary()); |
|
98 | 138 |
Registration reg = dto.registration(); |
99 | 139 |
registrationsByUUID.put(dto.getUuid(), reg); |
100 | 140 |
registrationsByRegID.put(reg.getId(), reg); |
Also available in: Unified diff
ref #6169 switching from mock Registration to Registration class in cdmlib