Project

General

Profile

« Previous | Next » 

Revision 2d981b4e

Added by Andreas Kohlbecker about 7 years ago

ref #6169 RegistrationWorkingSets more complete, validation problems accessible via UI

View differences:

src/main/java/eu/etaxonomy/cdm/mock/Registration.java
56 56
    public Registration() {
57 57
        super();
58 58
        status = RegistrationStatus.values()[(int) (Math.random() * RegistrationStatus.values().length)];
59
        specificIdentifier = Integer.toString(idAutoincrement++);
59
        setId(idAutoincrement++);
60
        specificIdentifier = Integer.toString(getId());
60 61
        identifier = "http://pyhcobank.org/" + specificIdentifier;
61 62
        registrationDate = DateTime.now();
62 63
    }
src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java
8 8
*/
9 9
package eu.etaxonomy.cdm.mock;
10 10

  
11
import java.util.ArrayList;
11 12
import java.util.Collection;
12 13
import java.util.HashMap;
13 14
import java.util.HashSet;
14 15
import java.util.List;
15 16
import java.util.Map;
16
import java.util.Set;
17 17
import java.util.UUID;
18 18

  
19
import org.apache.log4j.Logger;
20 19
import org.springframework.beans.factory.annotation.Autowired;
21 20
import org.springframework.beans.factory.annotation.Qualifier;
22 21
import org.springframework.stereotype.Service;
......
27 26
import eu.etaxonomy.cdm.model.common.CdmBase;
28 27
import eu.etaxonomy.cdm.model.name.Rank;
29 28
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
29
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
30 30
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
31 31
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationValidationException;
32 32

  
......
49 49
    private CdmRepository repo;
50 50

  
51 51
    private Map<UUID, Registration> registrationsByUUID = new HashMap<>();
52
    private Map<String, Registration> registrationsByRegID = new HashMap<>();
53
    private Map<String, RegistrationDTO> registrationDTOsByRegID = new HashMap<>();
54
    private Map<Integer, Set<RegistrationDTO>> registrationDTOsByCitationID = new HashMap<>();
52
    private Map<Integer, Registration> registrationsByRegID = new HashMap<>();
53
    private Map<Integer, RegistrationDTO> registrationDTOsById = new HashMap<>();
54
    private Map<String, RegistrationDTO> registrationDTOsByIdentifier = new HashMap<>();
55
    private Map<Integer, List<RegistrationDTO>> registrationDTOsByCitationId = new HashMap<>();
55 56

  
56 57
    private Collection<CdmBase> cdmEntities = new HashSet<>();
57 58

  
......
75 76
                            Registration nameReg = new Registration();
76 77
                            nameReg.setName(name);
77 78
                            cdmEntities.add(name);
78
                            try {
79
                                put(nameReg, new RegistrationDTO(nameReg));
80
                            } catch (RegistrationValidationException e) {
81
                                //FIXME throw  and handle Exception
82
                                Logger.getLogger(this.getClass()).error(e);
83
                            }
79
                            put(new RegistrationDTO(nameReg));
84 80

  
85 81
                            // typedesignation
86 82
                            Registration typedesignationReg = new Registration();
87 83
                            typedesignationReg.addTypeDesignations(name.getTypeDesignations());
88 84
                            cdmEntities.addAll(name.getTypeDesignations());
89
                            try {
90
                                put(typedesignationReg,  new RegistrationDTO(typedesignationReg));
91
                            } catch (RegistrationValidationException e) {
92
                                //FIXME throw  and handle Exception
93
                                Logger.getLogger(this.getClass()).error(e);
94
                            }
85
                            put(new RegistrationDTO(typedesignationReg));
95 86
                        }
96 87
                    }
97 88
                }
......
103 94
    /**
104 95
     * @param reg
105 96
     */
106
    private void put(Registration reg, RegistrationDTO dto) {
107
        registrationsByUUID.put(reg.getUuid(), reg);
108
        registrationsByRegID.put(reg.getSpecificIdentifier(), reg);
109
        registrationDTOsByRegID.put(reg.getSpecificIdentifier(), dto);
110
        if(! registrationDTOsByCitationID.containsKey(dto.getCitationID())){
111
            registrationDTOsByCitationID.put(dto.getCitationID(), new HashSet<RegistrationDTO>());
97
    private void put(RegistrationDTO dto) {
98
        Registration reg = dto.registration();
99
        registrationsByUUID.put(dto.getUuid(), reg);
100
        registrationsByRegID.put(reg.getId(), reg);
101

  
102
        registrationDTOsById.put(reg.getId(), dto);
103
        registrationDTOsByIdentifier.put(reg.getIdentifier(), dto);
104

  
105
        if(! registrationDTOsByCitationId.containsKey(dto.getCitationID())){
106
            registrationDTOsByCitationId.put(dto.getCitationID(), new ArrayList<RegistrationDTO>());
112 107
        }
113
        registrationDTOsByCitationID.get(dto.getCitationID()).add(dto);
108
        registrationDTOsByCitationId.get(dto.getCitationID()).add(dto);
114 109
    }
115 110

  
116 111
    private void mergeBack(){
......
125 120
        return registrationsByUUID.get(uuid);
126 121
    }
127 122

  
123

  
128 124
    public Collection<Registration> list(){
129 125
        init();
130 126
        return registrationsByUUID.values();
......
132 128

  
133 129
    public Collection<RegistrationDTO> listDTOs() {
134 130
        init();
135
        return registrationDTOsByRegID.values();
131
        return registrationDTOsById.values();
132
    }
133

  
134
    public Map<Integer, List<RegistrationDTO>> listDTOsByWorkingSet() {
135
        init();
136
        return registrationDTOsByCitationId;
137
    }
138

  
139
    /**
140
     * @param  id the CDM Entity id
141
     * @return
142
     */
143
    public Registration loadByRegistrationID(Integer id) {
144
        init();
145
        return registrationsByRegID.get(id);
136 146
    }
137 147

  
138
    public Map<Integer, Set<RegistrationDTO>> listDTOsByWorkingSet() {
148
    /**
149
     * @param identifier the Registration Identifier String
150
     * @return
151
     */
152
    public RegistrationDTO loadDtoByIdentifier(String identifier) {
139 153
        init();
140
        return registrationDTOsByCitationID;
154
        return registrationDTOsById.get(identifier);
141 155
    }
142 156

  
143 157
    /**
144
     * @param registrationID
158
     * @param id the CDM Entity id
145 159
     * @return
146 160
     */
147
    public Registration loadByRegistrationID(Integer registrationID) {
161
    public RegistrationDTO loadDtoById(Integer id) {
148 162
        init();
149
        return registrationsByRegID.get(registrationID.toString());
163
        return registrationDTOsById.get(id);
164
    }
165

  
166
    /**
167
     * @param  id the CDM Entity id
168
     * @return
169
     * @throws RegistrationValidationException
170
     */
171
    public RegistrationWorkingSet loadWorkingSetByRegistrationID(Integer id) throws RegistrationValidationException {
172
        init();
173
        RegistrationDTO dto = registrationDTOsById.get(id);
174

  
175
        return new RegistrationWorkingSet(registrationDTOsByCitationId.get(dto.getCitationID()));
150 176
    }
151 177

  
152 178

  
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItem.java
22 22
import com.vaadin.ui.Link;
23 23
import com.vaadin.ui.themes.ValoTheme;
24 24

  
25
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
25 26
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
26 27
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationType;
27 28
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
......
131 132
        updateTypeStateLabel();
132 133
        getCitationSummaryLabel().setValue(regDto.getCitationString() + "</br>" + regDto.getSummary());
133 134
        updateIdentifierLink();
134
        getOpenButton().addClickListener(e -> parentView.getEventBus().publishEvent(new NavigationEvent(
135

  
136
        // Buttons
137
        getOpenButton().addClickListener(e -> publishEvent(new NavigationEvent(
135 138
                RegistrationWorkflowViewBean.NAME,
136 139
                RegistrationWorkflowViewBean.ACTION_EDIT,
137
                regDto.getSpecificIdentifier().toString()
140
                Integer.toString(regDto.getId())
138 141
                )));
142
        if(regDto.getMessages().size() > 0){
143
            getMessageButton().setEnabled(true);
144
            getMessageButton().addStyleName(ValoTheme.BUTTON_FRIENDLY);
145
            getMessageButton().addClickListener(e -> publishEvent(
146
                    new ShowDetailsEvent<RegistrationDTO, Integer>(
147
                            e,
148
                            RegistrationDTO.class,
149
                            regDto.getId(),
150
                            "messages"))
151
                    );
152
        }
153

  
139 154
        updateDateLabels();
140 155
    }
141 156

  
......
162 177
     *
163 178
     */
164 179
    private void updateIdentifierLink() {
165
        getIdentifierLink().setResource(new ExternalResource(regDto.getRegistrationId()));
180
        getIdentifierLink().setResource(new ExternalResource(regDto.getIdentifier()));
166 181
        //TODO make responsive and use specificIdetifier in case the space gets too narrow
167
        getIdentifierLink().setCaption(regDto.getRegistrationId());
182
        getIdentifierLink().setCaption(regDto.getIdentifier());
168 183
    }
169 184

  
170 185
    /**
......
179 194
        }
180 195
    }
181 196

  
197
    private void publishEvent(Object event) {
198
        parentView.getEventBus().publishEvent(event);
199
    }
200

  
182 201
    /* ====== RegistrationItemDesign Getters ====== */
183 202
    /**
184 203
     * @return the typeStateLabel
src/main/java/eu/etaxonomy/cdm/vaadin/event/ShowDetailsEvent.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.vaadin.event;
10

  
11
import com.vaadin.ui.Component.Event;
12

  
13
/**
14
 * A request to display the details of the <code>property</code> for an object of
15
 * the class <code>entityType</code> which is uniquely identified by the <code>identifier</code>
16
 * This event is usually passed from a view to the according presenter implementation
17
 * which is capable of retrieving the details based on the <code>entityType</code> +
18
 * <code>identifier</code> + <code>property</code> and which should in turn pass the
19
 * extracted details data to the view for display.
20
 *
21
 * @author a.kohlbecker
22
 * @since Mar 24, 2017
23
 *
24
 */
25
public class ShowDetailsEvent<T extends Object, I extends Object> {
26

  
27
    private Event source;
28
    private Class<T> entityType;
29
    private I identifier;
30
    private String property;
31

  
32
    /**
33
     *
34
     * @param e
35
     * @param identifier
36
     * @param property
37
     */
38
    public ShowDetailsEvent(Event e, Class<T> entityType , I identifier, String property) {
39
        this.source = e;
40
        this.entityType = entityType;
41
        this.identifier = identifier;
42
        this.property = property;
43
    }
44

  
45
    /**
46
     * @return the source
47
     */
48
    public Event getSource() {
49
        return source;
50
    }
51

  
52
    /**
53
     * @return the type
54
     */
55
    public Class<T> getType() {
56
        return entityType;
57
    }
58

  
59
    /**
60
     * @return the identifier
61
     */
62
    public I getIdentifier() {
63
        return identifier;
64
    }
65

  
66
    /**
67
     * @return the property
68
     */
69
    public String getProperty() {
70
        return property;
71
    }
72

  
73

  
74

  
75
}
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/RegistrationWorkingSet.java
14 14
import java.util.Set;
15 15

  
16 16
import eu.etaxonomy.cdm.mock.Registration;
17
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
17 18
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
18 19
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationValidationException;
19 20

  
......
24 25
 */
25 26
public class RegistrationWorkingSet {
26 27

  
27
    private Set<Registration> registrations = new HashSet<>();
28
    private List<RegistrationDTO> registrationDTOs = new ArrayList<>();
28 29

  
29 30
    private int citationId = -1;
30 31

  
31 32
    private String citation = null;
32 33

  
33
    public RegistrationWorkingSet(Set<Registration> registrations) throws RegistrationValidationException {
34
    /**
35
     * Creates an empty working set
36
     */
37
    public RegistrationWorkingSet() {
38

  
39
    }
34 40

  
35
        validateAndAdd(registrations);
41
    public RegistrationWorkingSet(List<RegistrationDTO> registrationDTOs) throws RegistrationValidationException {
42
        validateAndAddDTOs(registrationDTOs, null);
36 43
    }
37 44

  
38 45
    /**
......
40 47
     * @throws RegistrationValidationException
41 48
     *
42 49
     */
43
    private void validateAndAdd(Set<Registration> candidated) throws RegistrationValidationException {
44
        List<String> problems = new ArrayList<>();
45
        for(Registration reg : candidated){
46
            try {
47
                RegistrationDTO regDto = new RegistrationDTO(reg);
50
    private void validateAndAdd(Set<Registration> candidates) throws RegistrationValidationException {
51
        List<RegistrationDTO> dtos = new ArrayList<>(registrationDTOs.size());
52
        candidates.forEach(reg -> dtos.add(new RegistrationDTO(reg)));
53
        validateAndAddDTOs(dtos, null);
54
    }
55

  
56
    /**
57
     * Validate and add all Registrations to the working set which are referring to the same publication
58
     * which is either the citation of the nomenclatural reference of the {@link TaxonNameBase} or the
59
     * citation of the {@link TypeDesignations}. Registration with a differing publication are not added to
60
     * the working set, instead a {@link RegistrationValidationException} is thrown which is a container for
61
     * all validation problems.
62
     *
63
     * @param candidates
64
     * @param problems Problems detected in prior validation and processing passed to this method to be completed.
65
     * @throws RegistrationValidationException
66
     */
67
    private void validateAndAddDTOs(List<RegistrationDTO> candidates, List<String> problems) throws RegistrationValidationException {
68
        if(problems == null){
69
            problems = new ArrayList<>();
70
        }
71
        for(RegistrationDTO regDto : candidates){
48 72
                if(citationId == -1){
49 73
                    citationId = regDto.getCitationID();
50 74
                    citation = regDto.getCitation();
51 75
                } else {
52 76
                    if(regDto.getCitationID() != citationId){
53
                        problems.add("Removing Registration " + reg.toString() + " from set since this refers to a different citation.\n");
77
                        problems.add("Removing Registration " + regDto.registration().toString() + " from set since this refers to a different citation.");
54 78
                        continue;
55 79
                    }
56 80
                }
57
                this.registrations.add(reg);
58

  
59
            } catch (RegistrationValidationException e) {
60
                problems.add(e.getMessage());
61
            }
81
                this.registrationDTOs.add(regDto);
62 82
        }
63 83

  
64 84
        if(!problems.isEmpty()){
65
            throw new RegistrationValidationException(problems.toString());
85
            throw new RegistrationValidationException("", problems);
66 86
        }
67 87

  
68 88
    }
69 89

  
70
    public boolean add(Registration registration){
71
        return registrations.add(registration);
90
    /**
91
     * @param reg
92
     * @throws RegistrationValidationException
93
     */
94
    public void add(Registration reg) throws RegistrationValidationException {
95
        Set<Registration> candidates = new HashSet<>();
96
        candidates.add(reg);
97
        validateAndAdd(candidates);
98
    }
99

  
100
    /**
101
     * @return the registrations
102
     */
103
    public List<Registration> getRegistrations() {
104
        List<Registration> regs = new ArrayList<>(registrationDTOs.size());
105
        registrationDTOs.forEach(dto -> regs.add(dto.registration()));
106
        return regs;
72 107
    }
73 108

  
74 109
    /**
75 110
     * @return the registrations
76 111
     */
77
    public Set<Registration> getRegistrations() {
78
        return registrations;
112
    public List<RegistrationDTO> getRegistrationDTOs() {
113
        return registrationDTOs;
79 114
    }
80 115

  
81 116
    /**
......
94 129

  
95 130

  
96 131

  
132

  
97 133
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/ListPresenter.java
11 11
import java.util.Collection;
12 12

  
13 13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.context.event.EventListener;
14 15

  
15 16
import com.vaadin.spring.annotation.SpringComponent;
16 17
import com.vaadin.spring.annotation.ViewScope;
17 18

  
18 19
import eu.etaxonomy.cdm.mock.RegistrationService;
20
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
19 21
import eu.etaxonomy.cdm.vaadin.view.registration.ListView;
20 22
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
21 23

  
......
45 47
        return dtos;
46 48
    }
47 49

  
50
    @EventListener(classes=ShowDetailsEvent.class) // (condition = "#event.entityType == eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO")
51
    public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
52
        RegistrationDTO regDto = serviceMock.loadDtoById((Integer)event.getIdentifier());
53
        if(event.getProperty().equals("messages")){
54
            getView().openDetailsPopup("Messages", regDto.getMessages());
55
        }
56
    }
57

  
48 58
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationDTO.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.presenter.registration;
10 10

  
11
import java.util.ArrayList;
11 12
import java.util.HashSet;
13
import java.util.List;
12 14
import java.util.Set;
15
import java.util.UUID;
13 16

  
14 17
import org.joda.time.DateTime;
15 18

  
......
33 36

  
34 37
    private Registration reg;
35 38

  
36
    static int idAutoincrement = 100000;
39
    private List<String> messages = new ArrayList<>();
37 40

  
38 41
    private Set<Registration> blockedBy = new HashSet<>();
39 42

  
......
42 45
    /**
43 46
     * @param reg
44 47
     * @param typifiedName should be provided in for Registrations for TypeDesignations
45
     * @throws RegistrationValidationException in case of inconsistencies in the Registration
46 48
     */
47
    public RegistrationDTO(Registration reg) throws RegistrationValidationException {
49
    public RegistrationDTO(Registration reg) {
48 50

  
49 51
         this.reg = reg;
50 52

  
......
57 59
                citationID = citation.getId();
58 60
            }
59 61
        } else if(registrationType.isTypification()){
60
            typifiedName = findTypifiedName();
62
            try {
63
                typifiedName = findTypifiedName();
64
            } catch (RegistrationValidationException e) {
65
                messages.add("Validation errors: " + e.getMessage());
66
            }
61 67
            summary = new TypeDesignationConverter(reg.getTypeDesignations(), typifiedName)
62 68
                    .buildString().print();
63 69
            if(!reg.getTypeDesignations().isEmpty()){
......
70 76
        } else {
71 77
            summary = "- INVALID REGISTRATION -";
72 78
        }
79

  
80
        messages.add("dummy");
73 81
    }
74 82

  
75 83

  
76 84

  
77 85
    /**
86
     * FIXME use the validation framework validators and to store the validation problems!!!
87
     *
78 88
     * @return
79 89
     * @throws RegistrationValidationException
80 90
     */
81 91
    private TaxonNameBase<?,?> findTypifiedName() throws RegistrationValidationException {
82 92

  
83
        StringBuffer problems = new StringBuffer();
93
        List<String> problems = new ArrayList<>();
84 94

  
85 95
        TaxonNameBase<?,?> typifiedName = null;
86 96

  
......
89 99
            if(typeDesignation.getTypifiedNames().isEmpty()){
90 100

  
91 101
                //TODO instead throw RegistrationValidationException()
92
                problems.append(" - Missing typifiedName in " + typeDesignation.toString()).append("\n");
102
                problems.add("Missing typifiedName in " + typeDesignation.toString());
93 103
                continue;
94 104
            }
95 105
            if(typeDesignation.getTypifiedNames().size() > 1){
96 106
              //TODO instead throw RegistrationValidationException()
97
                problems.append(" - Multiple typifiedName in " + typeDesignation.toString()).append("\n");
107
                problems.add("Multiple typifiedName in " + typeDesignation.toString());
98 108
                continue;
99 109
            }
100 110
            if(typifiedName == null){
......
105 115
                TaxonNameBase<?,?> otherTypifiedName = typeDesignation.getTypifiedNames().iterator().next();
106 116
                if(typifiedName.getId() != otherTypifiedName.getId()){
107 117
                  //TODO instead throw RegistrationValidationException()
108
                    problems.append(" - Multiple typifiedName in " + typeDesignation.toString()).append("\n");
118
                    problems.add("Multiple typifiedName in " + typeDesignation.toString());
109 119
                }
110 120
            }
111 121

  
112 122
        }
113
        if(problems.length() > 0){
114
            throw new RegistrationValidationException("Inconsistent Registration entity. " + reg.toString() + " Problems:\n" + problems.toString());
123
        if(!problems.isEmpty()){
124
            // FIXME use the validation framework
125
            throw new RegistrationValidationException("Inconsistent Registration entity. " + reg.toString(), problems);
115 126
        }
116 127

  
117 128
        return typifiedName;
118 129
    }
119 130

  
131
    /**
132
     * Provides access to the Registration entity this DTO has been build from.
133
     * This method is purposely not a getter to hide the original Registration
134
     * from generic processes which are exposing, binding bean properties.
135
     *
136
     * @return
137
     */
138
    public Registration registration() {
139
        return reg;
140
    }
141

  
120 142

  
121 143
    /**
122 144
     * @return the summary
......
143 165

  
144 166

  
145 167
    /**
146
     * @return the registrationId
168
     * @return the identifier
147 169
     */
148
    public String getRegistrationId() {
170
    public String getIdentifier() {
149 171
        return reg.getIdentifier();
150 172
    }
151 173

  
152 174

  
175
    public int getId() {
176
        return reg.getId();
177
    }
178

  
179

  
180
    public UUID getUuid() {
181
        return reg.getUuid();
182
    }
183

  
153 184
    /**
154 185
     * @return the specificIdentifier
155 186
     */
......
196 227
        return citationID;
197 228
    }
198 229

  
230

  
231

  
232
    /**
233
     * @return
234
     */
235
    public List<String> getMessages() {
236
        return messages;
237
    }
238

  
199 239
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationValidationException.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.presenter.registration;
10 10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
11 14
/**
12 15
 * @author a.kohlbecker
13 16
 * @since Mar 23, 2017
14 17
 *
15 18
 */
19
@SuppressWarnings("serial")
16 20
public class RegistrationValidationException extends Exception {
17 21

  
22
    List<String> problems = new ArrayList<>();
23

  
18 24
    /**
19 25
     * @param message
20 26
     */
21
    public RegistrationValidationException(String message) {
27
    public RegistrationValidationException(String message, List<String> problems) {
22 28
        super(message);
29
        this.problems = problems;
30
    }
31

  
32
    @Override
33
    public String getMessage() {
34
        StringBuffer sb = new StringBuffer(super.getMessage()).append(" - Problems:");
35
        problems.forEach(p -> sb.append("- ").append(p).append("\n"));
36
        return sb.toString();
37
    }
38

  
39
    public List<String> getProblems() {
40
        return problems;
23 41
    }
24 42

  
25 43

  
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationWorkflowPresenter.java
12 12
import org.springframework.beans.factory.annotation.Autowired;
13 13
import org.springframework.context.event.EventListener;
14 14

  
15
import com.vaadin.server.SystemError;
15 16
import com.vaadin.spring.annotation.SpringComponent;
16 17
import com.vaadin.spring.annotation.ViewScope;
17 18

  
......
21 22
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
22 23
import eu.etaxonomy.cdm.vaadin.event.ReferenceEvent;
23 24
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
25
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
24 26
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowView;
25 27
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
26 28

  
......
37 39
    @Autowired
38 40
    private RegistrationService serviceMock;
39 41

  
40
    private Registration registration;
42
    private RegistrationWorkingSet workingset;
41 43

  
42 44
    /**
43 45
     *
......
46 48
    }
47 49

  
48 50
    @EventListener
49
    protected void onRegistrationStartEvent(RegistrationWorkflowEvent e){
51
    protected void onRegistrationStartEvent(RegistrationWorkflowEvent event){
50 52

  
51
        if(registration != null){
52
            Logger.getLogger(RegistrationWorkflowPresenter.class).warn("Foiling attempt to start another registration in existing workflow");
53
        if(workingset != null){
54
            Logger.getLogger(RegistrationWorkflowPresenter.class).warn("Cant start a new workflow over an existing one.");
53 55
            return;
54 56
        }
55 57

  
56
        if(e.isStart()) {
57
            registration = new Registration();
58
            registration.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
59
            getView().setHeaderText("New " + e.getType().name().toString()+ " Registration");
58

  
59
        if(event.isStart()) {
60
            workingset = new RegistrationWorkingSet();
61
            Registration reg = new Registration();
62
            reg.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
63
            getView().setHeaderText("New " + event.getType().name().toString()+ " Registration");
64
            try {
65
                workingset.add(reg);
66
            } catch (RegistrationValidationException error) {
67
                getView().getWorkflow().setComponentError(new SystemError(error));
68
            }
60 69
        } else {
61
            registration = serviceMock.loadByRegistrationID(e.getRegistrationID());
62
            getView().setHeaderText("Registration " + registration.getIdentifier());
70
            try {
71
                workingset = serviceMock.loadWorkingSetByRegistrationID(event.getRegistrationID());
72
            } catch (RegistrationValidationException error) {
73
                getView().getWorkflow().setComponentError(new SystemError(error));
74
            }
75
            getView().setHeaderText("Registration for " + workingset.getCitation());
63 76
        }
64
        if(registration != null){
77
        if(workingset != null){
65 78
            // getView().getTitle().setValue("Workflow for a " + registrationType().name());
66
            getView().makeWorflow(registrationType());
79
            for(Registration reg : workingset.getRegistrations()){
80
                getView().makeWorflow(RegistrationType.from(reg));
81
            }
67 82
        }
68 83
    }
69 84

  
......
77 92
        getView().openReferenceEditor(null);
78 93
    }
79 94

  
80

  
81
    /**
82
     * @return
83
     */
84
    private RegistrationType registrationType() {
85
        return RegistrationType.from(registration);
86
    }
87

  
88

  
89

  
90 95
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListView.java
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11 11
import java.util.Collection;
12
import java.util.List;
12 13

  
13 14
import eu.etaxonomy.cdm.vaadin.presenter.registration.ListPresenter;
14 15
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
......
26 27
     */
27 28
    void populate(Collection<RegistrationDTO> registrations);
28 29

  
30
    /**
31
     * @param messages
32
     */
33
    void openDetailsPopup(String caption, List<String> messages);
34

  
29 35

  
30 36
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListViewBean.java
10 10

  
11 11
import java.util.ArrayList;
12 12
import java.util.Collection;
13
import java.util.List;
13 14

  
14 15
import org.springframework.beans.factory.annotation.Autowired;
15 16

  
......
19 20
import com.vaadin.data.util.PropertyValueGenerator;
20 21
import com.vaadin.navigator.View;
21 22
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
23
import com.vaadin.server.Page;
22 24
import com.vaadin.shared.ui.grid.HeightMode;
23 25
import com.vaadin.spring.annotation.SpringView;
24 26
import com.vaadin.ui.Button;
......
28 30
import com.vaadin.ui.Grid;
29 31
import com.vaadin.ui.Grid.Column;
30 32
import com.vaadin.ui.Grid.SelectionMode;
33
import com.vaadin.ui.Notification;
31 34
import com.vaadin.ui.renderers.ButtonRenderer;
32 35
import com.vaadin.ui.renderers.DateRenderer;
33 36
import com.vaadin.ui.renderers.HtmlRenderer;
......
181 184

  
182 185
        Column summaryColumn = grid.addColumn("summary");
183 186

  
184
        Column regidColumn = grid.addColumn("registrationId");
187
        Column regidColumn = grid.addColumn("identifier");
185 188
        regidColumn.setHeaderCaption("Id");
186 189
        regidColumn.setRenderer(new HtmlRenderer(), new UrlStringConverter("http://pyhcobank.org/"));
187 190

  
......
213 216
    public void populateList(Collection<RegistrationDTO> registrations) {
214 217

  
215 218
        for(RegistrationDTO regDto : registrations) {
216
            Component lazyItem = new RegistrationItem(regDto, this); //new LazyLoadWrapper(new RegistrationItem(regDto, this));
217
            lazyItem.setWidth(100, Unit.PERCENTAGE);
218
            listContainer.addComponent(lazyItem);
219
            Component item = new RegistrationItem(regDto, this);
220
            item.setWidth(100, Unit.PERCENTAGE);
221
            listContainer.addComponent(item);
219 222
        }
220 223
    }
221 224

  
225
    @Override
226
    public void openDetailsPopup(String caption, List<String> messages){
227
        StringBuffer sb = new StringBuffer();
228
        sb.append("<div class=\"details-popup-content\">");
229
        messages.forEach(s -> sb.append(s).append("</br>"));
230
        sb.append("</div>");
231
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
232
    }
233

  
222 234
    /**
223 235
     * @param registrationItems
224 236
     * @return

Also available in: Unified diff