Project

General

Profile

« Previous | Next » 

Revision 8d871fb1

Added by Andreas Kohlbecker about 7 years ago

avoiding problems in Registration mock service initalization

View differences:

src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java
15 15
import java.util.Map;
16 16
import java.util.UUID;
17 17

  
18
import javax.annotation.PostConstruct;
19

  
20 18
import org.springframework.beans.factory.annotation.Autowired;
21 19
import org.springframework.beans.factory.annotation.Qualifier;
22 20
import org.springframework.stereotype.Service;
......
54 52

  
55 53
    int minTypeDesignationCount = 1;
56 54

  
57
    @PostConstruct
58 55
    protected void init(){
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() != null && 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));
56
        if(registrationsByUUID.size() == 0){
57
            TransactionStatus tx = repo.startTransaction(true);
58
            while(registrationsByUUID.size() < 20){
59
                List<TaxonNameBase> names = repo.getNameService().list(TaxonNameBase.class, 100, 0, null, null);
60
                for(TaxonNameBase name : names){
61
                    if(name != null && name.getRank() != null && name.getRank().isLower(Rank.SUBFAMILY())){
62
                        if(name.getTypeDesignations().size() > minTypeDesignationCount - 1) {
63

  
64
                            // name
65
                            Registration nameReg = new Registration();
66
                            nameReg.setName(name);
67
                            cdmEntities.add(name);
68
                            put(nameReg, new RegistrationDTO(nameReg, null));
69

  
70
                            // typedesignation
71
                            Registration typedesignationReg = new Registration();
72
                            typedesignationReg.addTypeDesignations(name.getTypeDesignations());
73
                            cdmEntities.addAll(name.getTypeDesignations());
74
                            put(typedesignationReg,  new RegistrationDTO(typedesignationReg, name));
75
                        }
77 76
                    }
78 77
                }
79 78
            }
79
            repo.commitTransaction(tx);
80 80
        }
81
        repo.commitTransaction(tx);
82 81
    }
83 82

  
84 83
    /**
......
98 97
     * {@inheritDoc}
99 98
     */
100 99
    public Registration load(UUID uuid) {
100
        init();
101 101
        return registrationsByUUID.get(uuid);
102 102
    }
103 103

  
104 104
    public Collection<Registration> list(){
105
        init();
105 106
        return registrationsByUUID.values();
106 107
    }
107 108

  
108 109
    public Collection<RegistrationDTO> listDTOs() {
110
        init();
109 111
        return registrationDTOsByRegID.values();
110 112
    }
111 113

  
......
114 116
     * @return
115 117
     */
116 118
    public Registration loadByRegistrationID(Integer registrationID) {
119
        init();
117 120
        return registrationsByRegID.get(registrationID.toString());
118 121
    }
119 122

  

Also available in: Unified diff