Project

General

Profile

Revision fe8fe1e2

IDfe8fe1e286be0a14d8ff9385adfb209eb6c7e64a
Parent ae269e4d
Child c4f5e696

Added by Andreas Kohlbecker over 2 years ago

ref #6169 switching from mock Registration to Registration class in cdmlib

View differences:

src/main/java/eu/etaxonomy/cdm/mock/Registration.java
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.HashSet;
13
import java.util.Set;
14

  
15
import org.joda.time.DateTime;
16

  
17
import eu.etaxonomy.cdm.model.agent.Institution;
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19
import eu.etaxonomy.cdm.model.common.User;
20
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
22

  
23
/**
24
 * @author a.kohlbecker
25
 * @since Mar 10, 2017
26
 *
27
 */
28
public class Registration extends CdmBase {
29

  
30
    private static final long serialVersionUID = -7214477130043178680L;
31

  
32
    private String identifier;
33

  
34
    private String specificIdentifier;   //id without http-domain
35

  
36
    private DateTime registrationDate;
37

  
38
    private RegistrationStatus status;
39

  
40
    private Institution institution;
41

  
42
    private TaxonNameBase name;
43

  
44
    private Set<TypeDesignationBase> typeDesignations = new HashSet<>();
45

  
46
    private Set<Registration> blockedBy = new HashSet<>();
47

  
48
    private User submitter;
49

  
50
    static int idAutoincrement = 100000;
51

  
52

  
53
    /**
54
     * @param NAME
55
     */
56
    public Registration() {
57
        super();
58
        status = RegistrationStatus.values()[(int) (Math.random() * RegistrationStatus.values().length)];
59
        setId(idAutoincrement++);
60
        specificIdentifier = Integer.toString(getId());
61
        identifier = "http://pyhcobank.org/" + specificIdentifier;
62
        registrationDate = DateTime.now();
63
    }
64

  
65
    /**
66
     * @return the identifier
67
     */
68
    public String getIdentifier() {
69
        return identifier;
70
    }
71

  
72
    /**
73
     * @param identifier the identifier to set
74
     */
75
    public void setIdentifier(String identifier) {
76
        this.identifier = identifier;
77
    }
78

  
79
    /**
80
     * @return the specificIdentifier
81
     */
82
    public String getSpecificIdentifier() {
83
        return specificIdentifier;
84
    }
85

  
86
    /**
87
     * @param specificIdentifier the specificIdentifier to set
88
     */
89
    public void setSpecificIdentifier(String specificIdentifier) {
90
        this.specificIdentifier = specificIdentifier;
91
    }
92

  
93
    /**
94
     * @return the registrationDate
95
     */
96
    public org.joda.time.DateTime getRegistrationDate() {
97
        return registrationDate;
98
    }
99

  
100
    /**
101
     * @param registrationDate the registrationDate to set
102
     */
103
    public void setRegistrationDate(org.joda.time.DateTime registrationDate) {
104
        this.registrationDate = registrationDate;
105
    }
106

  
107
    /**
108
     * @return the status
109
     */
110
    public RegistrationStatus getStatus() {
111
        return status;
112
    }
113

  
114
    /**
115
     * @param status the status to set
116
     */
117
    public void setStatus(RegistrationStatus status) {
118
        this.status = status;
119
    }
120

  
121
    /**
122
     * @return the institution
123
     */
124
    public Institution getInstitution() {
125
        return institution;
126
    }
127

  
128
    /**
129
     * @param institution the institution to set
130
     */
131
    public void setInstitution(Institution institution) {
132
        this.institution = institution;
133
    }
134

  
135
    /**
136
     * @return the name
137
     */
138
    public TaxonNameBase getName() {
139
        return name;
140
    }
141

  
142
    /**
143
     * @param name the name to set
144
     */
145
    public void setName(TaxonNameBase name) {
146
        this.name = name;
147
    }
148

  
149
    /**
150
     * @return the submitter
151
     */
152
    public User getSubmitter() {
153
        return submitter;
154
    }
155

  
156
    /**
157
     * @param submitter the submitter to set
158
     */
159
    public void setSubmitter(User submitter) {
160
        this.submitter = submitter;
161
    }
162

  
163
    public boolean addTypeDesignation(TypeDesignationBase typeDesignation){
164
        return this.typeDesignations.add(typeDesignation);
165
    }
166

  
167
    public boolean addTypeDesignations(Collection<TypeDesignationBase> typeDesignations){
168
        return this.typeDesignations.addAll(typeDesignations);
169
    }
170

  
171
    public boolean addBlockedBy(Registration registration){
172
        return blockedBy.add(registration);
173
    }
174

  
175
    /**
176
     * @return the typeDesignations
177
     */
178
    public Set<TypeDesignationBase> getTypeDesignations() {
179
        return typeDesignations;
180
    }
181

  
182
    /**
183
     * @return the blockedBy
184
     */
185
    public Set<Registration> getBlockedBy() {
186
        return blockedBy;
187
    }
188

  
189

  
190

  
191

  
192

  
193

  
194
}
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
                }
......
92 109
    }
93 110

  
94 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

  
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);
src/main/java/eu/etaxonomy/cdm/mock/RegistrationStatus.java
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
public enum RegistrationStatus {
12

  
13
    PREPARATION,// A new record which is being edited by the Author
14
    CURATION, //A record ready for the curator to be validated.
15
    READY, //The record has passed the validation by the curator and is ready for publication.
16
    PUBLISHED, //The name or typification has finally been published.
17
    REJECTED //The registration has been rejected, the process is aborted and the record is preserved.
18

  
19
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/TypeStateLabel.java
17 17
import com.vaadin.shared.ui.label.ContentMode;
18 18
import com.vaadin.ui.Label;
19 19

  
20
import eu.etaxonomy.cdm.mock.RegistrationStatus;
20
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
21 21
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationType;
22 22

  
23 23
/**
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/RegistrationWorkingSet.java
15 15

  
16 16
import org.joda.time.DateTime;
17 17

  
18
import eu.etaxonomy.cdm.mock.Registration;
19
import eu.etaxonomy.cdm.mock.RegistrationStatus;
18
import eu.etaxonomy.cdm.model.name.Registration;
19
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
20 20
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21 21
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
22 22
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationValidationException;
......
76 76
        for(RegistrationDTO regDto : candidates){
77 77
                if(citationId == null){
78 78
                    citationId = regDto.getCitationID();
79
                    citation = regDto.getCitation();
79
                    citation = regDto.getCitationString();
80 80
                } else {
81 81
                    if(regDto.getCitationID() != citationId){
82 82
                        problems.add("Removing Registration " + regDto.registration().toString() + " from set since this refers to a different citation.");
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/WorkflowStep.java
10 10

  
11 11
import org.apache.commons.lang.StringEscapeUtils;
12 12

  
13
import eu.etaxonomy.cdm.mock.RegistrationStatus;
13
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
14

  
14 15

  
15 16
/**
16 17
 * @author a.kohlbecker
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationDTO.java
14 14
import java.util.Set;
15 15
import java.util.UUID;
16 16

  
17
import org.apache.log4j.Logger;
17 18
import org.joda.time.DateTime;
18 19

  
19
import eu.etaxonomy.cdm.mock.Registration;
20
import eu.etaxonomy.cdm.mock.RegistrationStatus;
21 20
import eu.etaxonomy.cdm.model.common.TimePeriod;
21
import eu.etaxonomy.cdm.model.name.Registration;
22
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
22 23
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23 24
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
24 25
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.reference.IReference;
26 27
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationConverter;
27 28

  
28 29
public class RegistrationDTO{
29 30

  
31
    private static final Logger logger = Logger.getLogger(RegistrationDTO.class);
32

  
30 33
    private String summary = "";
31 34

  
32
    private String citationString = "";
35
    private RegistrationType registrationType;
33 36

  
34
    private int citationID;
37
    private IReference citation = null;
35 38

  
36
    private RegistrationType registrationType;
39
    private String citationDetail = null;
37 40

  
38 41
    private Registration reg;
39 42

  
40 43
    private List<String> messages = new ArrayList<>();
41 44

  
42
    private Set<Registration> blockedBy = new HashSet<>();
45
    private Set<eu.etaxonomy.cdm.model.name.Registration> blockedBy = new HashSet<>();
43 46

  
44 47
    private TaxonNameBase<?, ?> typifiedName;
45 48

  
46
    private TimePeriod datePublished;
47

  
48 49
    /**
49 50
     * @param reg
50 51
     * @param typifiedName should be provided in for Registrations for TypeDesignations
......
53 54

  
54 55
         this.reg = reg;
55 56

  
56
        registrationType = RegistrationType.from(reg);
57
        if(registrationType.isName()){
58
            summary = reg.getName().getTitleCache();
59
            INomenclaturalReference citation = reg.getName().getNomenclaturalReference();
60
            if(citation != null){
61
                citationString = citation.generateTitle();
62
                citationID = citation.getId();
63
                datePublished = citation.getDatePublished();
64
            }
65
        } else if(registrationType.isTypification()){
57
         registrationType = RegistrationType.from(reg);
58

  
59
        if(hasName(reg)){
60
            citation = reg.getName().getNomenclaturalReference();
61
            citationDetail = reg.getName().getNomenclaturalMicroReference();
62
        }
63
        if(hasTypifications(reg)){
66 64
            try {
67 65
                typifiedName = findTypifiedName();
68 66
            } catch (RegistrationValidationException e) {
69 67
                messages.add("Validation errors: " + e.getMessage());
70 68
            }
71
            summary = new TypeDesignationConverter(reg.getTypeDesignations(), typifiedName)
72
                    .buildString().print();
73 69
            if(!reg.getTypeDesignations().isEmpty()){
74
                Reference citation = reg.getTypeDesignations().iterator().next().getCitation();
75
                if(citation != null) {
76
                    citationString = citation.generateTitle();
77
                    citationID = citation.getId();
70
                if(citation == null) {
71
                    TypeDesignationBase first = reg.getTypeDesignations().iterator().next();
72
                    citation = first.getCitation();
73
                    citationDetail = first.getCitationMicroReference();
78 74
                }
79 75
            }
80
        } else {
81
            summary = "- INVALID REGISTRATION -";
82 76
        }
77
        switch(registrationType) {
78
        case EMPTY:
79
            summary = "BLANK REGISTRATION";
80
            break;
81
        case NAME:
82
            summary = reg.getName().getTitleCache();
83
            break;
84
        case NAME_AND_TYPIFICATION:
85
        case TYPIFICATION:
86
        default:
87
            summary = new TypeDesignationConverter(reg.getTypeDesignations(), typifiedName).buildString().print();
88
            break;
89
        }
90

  
91
        // trigger initialization of the reference
92
        getCitationString();
83 93

  
84
        messages.add("dummy");
85 94
    }
86 95

  
96
    /**
97
     * @param reg
98
     * @return
99
     */
100
    private boolean hasTypifications(Registration reg) {
101
        return reg.getTypeDesignations() != null && reg.getTypeDesignations().size() > 0;
102
    }
87 103

  
104
    /**
105
     * @param reg
106
     * @return
107
     */
108
    private boolean hasName(Registration reg) {
109
        return reg.getName() != null;
110
    }
88 111

  
89 112
    /**
90 113
     * FIXME use the validation framework validators and to store the validation problems!!!
......
136 159
     * Provides access to the Registration entity this DTO has been build from.
137 160
     * This method is purposely not a getter to hide the original Registration
138 161
     * from generic processes which are exposing, binding bean properties.
139
     *
162
     *IReference
140 163
     * @return
141 164
     */
142 165
    public Registration registration() {
......
151 174
        return summary;
152 175
    }
153 176

  
154

  
155 177
    /**
156 178
     * @return the registrationType
157 179
     */
......
159 181
        return registrationType;
160 182
    }
161 183

  
162

  
163 184
    /**
164 185
     * @return the status
165 186
     */
......
167 188
        return reg.getStatus();
168 189
    }
169 190

  
170

  
171 191
    /**
172 192
     * @return the identifier
173 193
     */
......
203 223
     * @return the registrationDate
204 224
     */
205 225
    public TimePeriod getDatePublished() {
206
        return datePublished;
226
        return citation == null ? null : citation.getDatePublished();
207 227
    }
208 228

  
209 229
    /**
......
213 233
        return reg.getCreated();
214 234
    }
215 235

  
216
    public String getCitation() {
217
        return citationString;
236
    public IReference getCitation() {
237
        return citation;
218 238
    }
219 239

  
220 240
    /**
221
     * @return the blockedBy
241
     * @return the citationID
222 242
     */
223
    public Set<Registration> getBlockedBy() {
224
        return blockedBy;
243
    public Integer getCitationID() {
244
        return citation == null ? null : citation.getId();
225 245
    }
226 246

  
227 247
    /**
228 248
     * @return the citationString
229 249
     */
230 250
    public String getCitationString() {
231
        return citationString;
251
        if(citation == null){
252
            return null;
253
        }
254
        if(INomenclaturalReference.class.isAssignableFrom(citation.getClass())){
255
            return ((INomenclaturalReference)citation).getNomenclaturalCitation(citationDetail);
256
        } else {
257
            logger.error("The citation is not a NomenclaturalReference");
258
            return citation.generateTitle();
259
        }
232 260
    }
233 261

  
234 262
    /**
235
     * @return the citationID
263
     * @return the blockedBy
236 264
     */
237
    public int getCitationID() {
238
        return citationID;
265
    public Set<Registration> getBlockedBy() {
266
        return blockedBy;
239 267
    }
240 268

  
241

  
242

  
243 269
    /**
244 270
     * @return
245 271
     */
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationType.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11
import eu.etaxonomy.cdm.mock.Registration;
11
import eu.etaxonomy.cdm.model.name.Registration;
12 12

  
13 13
/**
14 14
 * @author a.kohlbecker
......
17 17
 */
18 18
public enum RegistrationType {
19 19

  
20
    NAME, TYPIFICATION, INVALID;
20
    /**
21
     * A <code>Registration</code> for a new name
22
     */
23
    NAME,
24
    /**
25
     * A <code>Registration</code> for a new name and one or more according
26
     * typifications.
27
     */
28
    NAME_AND_TYPIFICATION,
29
    /**
30
     * A <code>Registration</code> for one or more typifications for an
31
     * previously published name.
32
     */
33
    TYPIFICATION,
34
    /**
35
     * A newly created <code>Registration</code> without any name and
36
     * typification.
37
     */
38
    EMPTY;
21 39

  
22 40
    /**
23 41
     * @param reg
24 42
     * @return
25 43
     */
26 44
    public static RegistrationType from(Registration reg) {
27
        if(reg.getName() != null){
45

  
46
        if (reg.getName() != null && reg.getTypeDesignations() != null && reg.getTypeDesignations().size() > 0) {
47
            return NAME_AND_TYPIFICATION;
48
        }
49
        if (reg.getName() != null) {
28 50
            return NAME;
29 51
        }
30
        if(reg.getTypeDesignations().size() > 0){
52
        if (reg.getTypeDesignations().size() > 0) {
31 53
            return TYPIFICATION;
32 54
        }
33
        return INVALID;
55
        return EMPTY;
34 56
    }
35 57

  
36 58
    /**
......
39 61
    public boolean isName() {
40 62
        return NAME.equals(this);
41 63

  
42
  }
64
    }
65

  
43 66
    /**
44 67
     * @return
45 68
     */
......
47 70
        return TYPIFICATION.equals(this);
48 71
    }
49 72

  
73
    /**
74
     * @return
75
     */
76
    public boolean isNameAndTypification() {
77
        return NAME_AND_TYPIFICATION.equals(this);
78
    }
79

  
80
    /**
81
     * @return
82
     */
83
    public boolean isEnmpty() {
84
        return EMPTY.equals(this);
85
    }
86

  
50 87
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowPresenter.java
20 20
import com.vaadin.spring.annotation.SpringComponent;
21 21
import com.vaadin.spring.annotation.ViewScope;
22 22

  
23
import eu.etaxonomy.cdm.mock.Registration;
24 23
import eu.etaxonomy.cdm.mock.RegistrationService;
25 24
import eu.etaxonomy.cdm.model.name.Rank;
25
import eu.etaxonomy.cdm.model.name.Registration;
26 26
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
27 27
import eu.etaxonomy.cdm.model.reference.Reference;
28 28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
......
66 66

  
67 67
        if(event.isStart()) {
68 68
            workingset = new RegistrationWorkingSet();
69
            Registration reg = new Registration();
69
            Registration reg = Registration.NewInstance();
70 70
            reg.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
71 71
            getView().setHeaderText("New " + event.getType().name().toString()+ " Registration");
72 72
            try {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)