Project

General

Profile

« Previous | Next » 

Revision c9ecf03d

Added by Andreas Kohlbecker over 6 years ago

renaming RegistrationWorkflowView to RegistrationWorksetView

View differences:

ide/eclipse/Jetty Launcher/cdm-vaadin - run.launch
54 54
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="net.sourceforge.eclipsejetty.launcher.JettyLaunchClassPathProvider"/>
55 55
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.sourceforge.eclipsejetty.starter.jetty9.Jetty9LauncherMain"/>
56 56
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="cdm-vaadin"/>
57
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dlog4j.configDebug=false&#10;-Dlog4j.configuration=file:///${system_property:user.home}/.cdmLibrary/log4j.properties&#10;&#10;-Dcdm.forceSchemaUpdate=true&#10;&#10;-Dcdm-vaadin.login.usr=admin&#10;-Dcdm-vaadin.login.pwd=00000"/>
57
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dlog4j.configDebug=false&#10;-Dlog4j.configuration=file:///${system_property:user.home}/.cdmLibrary/log4j.properties&#10;&#10;-Dcdm.forceSchemaUpdate=true"/>
58 58
</launchConfiguration>
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItem.java
38 38
import eu.etaxonomy.cdm.vaadin.util.formatter.TimePeriodFormatter;
39 39
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
40 40
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
41
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowViewBean;
41
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorksetViewBean;
42 42
import eu.etaxonomy.vaadin.mvp.AbstractView;
43 43
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
44 44

  
......
168 168
        NavigationEvent navigationEvent = null;
169 169
        if(regDto.getCitationID() != null) {
170 170
            navigationEvent = new NavigationEvent(
171
                    RegistrationWorkflowViewBean.NAME,
171
                    RegistrationWorksetViewBean.NAME,
172 172
                    Integer.toString(regDto.getCitationID())
173 173
                    );
174 174
        } else {
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowPresenter.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.view.registration;
10

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

  
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.context.event.EventListener;
16
import org.springframework.security.core.Authentication;
17

  
18
import com.vaadin.server.SystemError;
19
import com.vaadin.spring.annotation.SpringComponent;
20
import com.vaadin.spring.annotation.ViewScope;
21

  
22
import eu.etaxonomy.cdm.api.service.INameService;
23
import eu.etaxonomy.cdm.api.service.IRegistrationService;
24
import eu.etaxonomy.cdm.model.common.User;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.name.Registration;
27
import eu.etaxonomy.cdm.model.name.TaxonName;
28
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
29
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
32
import eu.etaxonomy.cdm.service.CdmStore;
33
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
34
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
35
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
36
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
37
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
38
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
39
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
40
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
41
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
42
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
43
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
44
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
45
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
46
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
47
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
48
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
49
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
50
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
51

  
52
/**
53
 * @author a.kohlbecker
54
 * @since Mar 3, 2017
55
 *
56
 */
57
@SpringComponent
58
@ViewScope
59
public class RegistrationWorkflowPresenter extends AbstractPresenter<RegistrationWorkflowView> {
60

  
61
    private static final long serialVersionUID = 1L;
62

  
63
    @Autowired
64
    private IRegistrationWorkingSetService workingSetService;
65

  
66
    /**
67
     * @return the workingSetService
68
     */
69
    public IRegistrationWorkingSetService getWorkingSetService() {
70
        ensureBoundConversation();
71
        return workingSetService;
72
    }
73

  
74
    private RegistrationWorkingSet workingset;
75

  
76
    private TaxonName newTaxonNameForRegistration = null;
77

  
78
    private RegistrationDTO newRegistrationDTOWithExistingName;
79

  
80

  
81
    /**
82
     *
83
     */
84
    public RegistrationWorkflowPresenter() {
85
    }
86

  
87

  
88
    /**
89
     * Always create a new Store
90
     *
91
     * @return
92
     */
93
    protected CdmStore<Registration, IRegistrationService> getRegistrationStore(){
94
        return new CdmStore<Registration, IRegistrationService>(getRepo(), getRepo().getRegistrationService());
95
    }
96

  
97
    /**
98
     * Always create a new Store
99
     *
100
     * @return
101
     */
102
    protected CdmStore<TaxonName, INameService> getTaxonNameStore(){
103
        return new  CdmStore<TaxonName, INameService>(getRepo(), getRepo().getNameService());
104
    }
105

  
106

  
107
    /**
108
     * @param taxonNameId
109
     * @return
110
     */
111
    protected Registration createNewRegistrationForName(Integer taxonNameId) {
112
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
        // move into RegistrationWorkflowStateMachine
114
        long identifier = System.currentTimeMillis();
115
        Registration reg = Registration.NewInstance(
116
                "http://phycobank.org/" + identifier,
117
                "" + identifier,
118
                taxonNameId != null ? getRepo().getNameService().find(taxonNameId) : null,
119
                null);
120
        Authentication authentication = currentSecurityContext().getAuthentication();
121
        reg.setSubmitter((User)authentication.getPrincipal());
122
        EntityChangeEvent event = getRegistrationStore().saveBean(reg);
123
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
        return getRepo().getRegistrationService().find(event.getEntityId());
125
    }
126

  
127

  
128
    /**
129
     *
130
     */
131
    protected void refreshView() {
132
        getConversationHolder().getSession().clear();
133
        presentWorkingSet(workingset.getCitationId());
134
    }
135

  
136

  
137
    /**
138
     * {@inheritDoc}
139
     */
140
    @Override
141
    public void handleViewEntered() {
142

  
143
        super.handleViewEntered();
144

  
145
        presentWorkingSet(getView().getCitationID());
146

  
147
        CdmFilterablePagingProvider<TaxonName> pagingProvider = new CdmFilterablePagingProvider<TaxonName>(
148
                getRepo().getNameService(), this);
149
        CdmTitleCacheCaptionGenerator<TaxonName> titleCacheGenrator = new CdmTitleCacheCaptionGenerator<TaxonName>();
150
        getView().getAddExistingNameCombobox().setCaptionGenerator(titleCacheGenrator);
151
        getView().getAddExistingNameCombobox().loadFrom(pagingProvider, pagingProvider, pagingProvider.getPageSize());
152
    }
153

  
154
    /**
155
     * Loads the WorkingSet from the data base and passes it to the view.
156
     *
157
     * @param registrationID
158
     */
159
    private void presentWorkingSet(Integer referenceID) {
160
        try {
161
            workingset = getWorkingSetService().loadWorkingSetByReferenceID(referenceID);
162
        } catch (RegistrationValidationException error) {
163
            getView().getWorkflow().setComponentError(new SystemError(error));
164
        }
165
        if(workingset == null || workingset.getCitationId() == null){
166
            Reference citation = getRepo().getReferenceService().find(referenceID);
167
            workingset = new RegistrationWorkingSet(citation);
168
        }
169
        // getView().setHeaderText("Registrations for " + workingset.getCitation());
170
        getView().setWorkingset(workingset);
171
    }
172

  
173
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD && #event.sourceComponent == null")
174
    public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
175
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
176
        popup.loadInEditor(null);
177
    }
178

  
179
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
180
    public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
181
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
182
        popup.withDeleteButton(true);
183
        popup.loadInEditor(event.getEntityId());
184
    }
185

  
186
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
187
    public void onRegistrationEditorAction(RegistrationEditorAction event) {
188
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class);
189
        popup.loadInEditor(event.getEntityId());
190
    }
191

  
192
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
193
    public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
194

  
195
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
196
        popup.withDeleteButton(true);
197
        // disable NomReferenceCombobox:
198
        // the in the registration application inReferences should only edited centrally
199
        popup.getNomReferenceCombobox().setEnabled(false);
200
        popup.loadInEditor(event.getEntityId());
201
    }
202

  
203
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
204
    public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
205

  
206
        newTaxonNameForRegistration = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
207
        newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
208
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration);
209
        newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
210
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
211
        popup.withDeleteButton(true);
212
        popup.loadInEditor(newTaxonNameForRegistration.getId());
213
        // disable NomReferenceCombobox:
214
        // the in the registration application inReferences should only edited centrally
215
        popup.getNomReferenceCombobox().setEnabled(false);
216
    }
217

  
218
    /**
219
     * Creates a new <code>Registration</code> for a new name that has just been edited
220
     * using the <code>TaxonNamePopupEditor</code>. The new name was previously created
221
     * in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
222
     * and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
223
     * (<code>Reason.CANCEL</code>).
224
     *
225
     *
226
     * @param event
227
     * @throws RegistrationValidationException
228
     */
229
    @EventListener
230
    public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
231
        if(event.getPopup() instanceof TaxonNamePopupEditor){
232
            if(newTaxonNameForRegistration != null && event.getReason().equals(Reason.SAVE)){
233
                int taxonNameId = newTaxonNameForRegistration.getId();
234
                Registration reg = createNewRegistrationForName(taxonNameId);
235
                workingset.add(reg);
236
                refreshView();
237
            } else if(event.getReason().equals(Reason.CANCEL)){
238
                // clean up
239
                getTaxonNameStore().deleteBean(newTaxonNameForRegistration);
240
            }
241
            newTaxonNameForRegistration = null;
242
        }
243
    }
244

  
245

  
246
    /**
247
     * Creates a new Registration for an exiting (previously published name).
248
     *
249
     * @param event
250
     * @throws RegistrationValidationException
251
     */
252
    @EventListener(condition = "#event.action == T(eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent.Action).start")
253
    public void onRegistrationWorkflowEventActionStart(RegistrationWorkflowEvent event) throws RegistrationValidationException {
254

  
255
        getView().getAddExistingNameCombobox().commit();
256
        TaxonName typifiedName = getView().getAddExistingNameCombobox().getValue();
257
        if(typifiedName != null){
258
            Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
259
            Reference citation = getRepo().getReferenceService().find(workingset.getCitationId());
260
            newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
261
            workingset.add(newRegistrationDTOWithExistingName);
262
            // tell the view to update the workingset
263
            getView().setWorkingset(workingset);
264
            getView().getAddExistingNameRegistrationButton().setEnabled(false);
265
            getView().getAddExistingNameRegistrationButton().setDescription("You first need to add a type designation to the previously created registration.");
266
        } else {
267
            logger.error("Seletced name is NULL");
268
        }
269

  
270
    }
271

  
272
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
273
    public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event) {
274

  
275
            if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
276
                SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
277
                popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getEntityId()));
278
            } else {
279
                // TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
280
                // FIXME implement NameTypeDesignationWorkingsetPopupEditor
281
            }
282
    }
283

  
284
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD && #event.sourceComponent == null")
285
    public void onAddNewTypeDesignationWorkingset(TypeDesignationWorkingsetEditorAction event) {
286

  
287
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
288
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
289
            TypeDesignationWorkingsetEditorIdSet identifierSet;
290
            Integer typifiedNameId;
291
            if(newRegistrationDTOWithExistingName != null){
292
                typifiedNameId = newRegistrationDTOWithExistingName.getTypifiedName().getId();
293
            } else {
294
                typifiedNameId = workingset.getRegistrationDTO(event.getRegistrationId())
295
                        .get()
296
                        .getTypifiedName()
297
                        .getId();
298
            }
299
            identifierSet = new TypeDesignationWorkingsetEditorIdSet(
300
                    event.getRegistrationId(),
301
                    getView().getCitationID(),
302
                    typifiedNameId
303
                    );
304
            popup.loadInEditor(identifierSet
305
                 );
306
            popup.withDeleteButton(true);
307
        } else {
308
            // TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
309
            // FIXME implement NameTypeDesignationWorkingsetPopupEditor
310
        }
311
    }
312

  
313
    /**
314
     * Performs final actions after a TypeDesignationEditor which has been
315
     * opened to add a TypeDesignation to a Registration object which was
316
     * created for an previously published name. Prior adding a typedesignation,
317
     * the according Registration object is dangling, that has no association to
318
     * any entity denoting an nomenclatural act which has a reference to a
319
     * publication. This means that the registration object is not in the
320
     * working set.
321
     *
322
     *
323
     * @param event
324
     * @throws RegistrationValidationException
325
     */
326
    @EventListener
327
    public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
328
        if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
329
            if(event.getReason().equals(Reason.SAVE)){
330
                 refreshView();
331
            } else if(event.getReason().equals(Reason.CANCEL)){
332
                // clean up
333
                if(newRegistrationDTOWithExistingName != null){
334
                    getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration());
335
                }
336
            }
337
            // set newRegistrationDTOWithExistingName NULL in any case
338
            newRegistrationDTOWithExistingName = null;
339
        }
340
    }
341

  
342

  
343
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
344
    public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
345
        List<String> messages = new ArrayList<>();
346
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
347
            dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
348
        }
349
        if(event.getProperty().equals("messages")){
350
            getView().openDetailsPopup("Messages", messages);
351
        }
352
    }
353

  
354
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
355
    public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
356
        RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
357
        if(event.getProperty().equals("messages")){
358
            if(getView() != null){
359
                getView().openDetailsPopup("Messages", regDto.getMessages());
360
            }
361
        }
362
    }
363

  
364
    @EventListener
365
    public void onEntityChangeEvent(EntityChangeEvent event){
366
        if(workingset == null){
367
            return;
368
        }
369
        if(Reference.class.isAssignableFrom(event.getEntityType())){
370
            if(workingset.getCitationId().equals(event.getEntityId())){
371
                refreshView();
372
            }
373
        } else
374
        if(Registration.class.isAssignableFrom(event.getEntityType())){
375
            if(workingset.getRegistrations().stream().anyMatch(reg -> reg.getId() == event.getEntityId())){
376
                refreshView();
377
            }
378
        } else
379
        if(TaxonName.class.isAssignableFrom(event.getEntityType())){
380
            if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
381
                reg.getTypifiedName() != null
382
                && reg.getTypifiedName().getId() == event.getEntityId())){
383
                    refreshView();
384
            }
385
        } else
386
        if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
387
            if(workingset.getRegistrationDTOs().stream().anyMatch(
388
                    reg -> reg.getTypeDesignations().stream().anyMatch(
389
                            td -> td.getId() == event.getEntityId()
390
                            )
391
                        )
392
                    ){
393
                refreshView();
394
            }
395
        }
396

  
397
    }
398

  
399
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowView.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.view.registration;
10

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

  
14
import org.vaadin.viritin.fields.LazyComboBox;
15

  
16
import com.vaadin.ui.AbstractLayout;
17
import com.vaadin.ui.Button;
18

  
19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
21
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
22
import eu.etaxonomy.vaadin.mvp.ApplicationView;
23

  
24
/**
25
 * @author a.kohlbecker
26
 * @since Mar 3, 2017
27
 *
28
 */
29
public interface RegistrationWorkflowView extends ApplicationView{
30

  
31
    public static final String ACTION_NEW = "new";
32

  
33
    public static final String ACTION_EDIT = "edit";
34

  
35

  
36
    AbstractLayout getWorkflow();
37

  
38

  
39
    /**
40
     * Open a popup editor for an existing TaxonName if the nameUuid is
41
     * given otherwise a blank editor will open if the  nameUuid is null.
42
     *
43
     * @param nameUuid can be null
44
     */
45
    void openNameEditor(UUID nameUuid);
46

  
47
    /**
48
     * Open a popup editor for an existing Reference if the referenceUuid is
49
     * given otherwise a blank editor will open if the  referenceUuid is null.
50
     *
51
     * @param referenceUuid can be null
52
     */
53
    void openReferenceEditor(UUID referenceUuid);
54

  
55
    /**
56
     * @param subheaderText
57
     */
58
    void setSubheaderText(String subheaderText);
59

  
60
    /**
61
     * @param subheaderText
62
     */
63
    void setHeaderText(String subheaderText);
64

  
65
    /**
66
     * @param workingset
67
     */
68
    void setWorkingset(RegistrationWorkingSet workingset);
69

  
70
    void addBlockingRegistration(RegistrationDTO blocking);
71

  
72
    /**
73
     * @param messages
74
     */
75
    void openDetailsPopup(String caption, List<String> messages);
76

  
77
    Button getAddNewNameRegistrationButton();
78

  
79
    /**
80
     * @return
81
     */
82
    Button getAddExistingNameRegistrationButton();
83

  
84
    public LazyComboBox<TaxonName> getAddExistingNameCombobox();
85

  
86
    Integer getCitationID();
87

  
88

  
89
    /**
90
     * selecting a type will cause a {@link TypeDesignationWorkingsetEditorAction} to be emitted.
91
     * On Cancel .. TODO
92
     * @param registrationEntityId
93
     */
94
    void chooseNewTypeRegistrationWorkingset(Integer registrationEntityId);
95

  
96

  
97

  
98

  
99

  
100

  
101

  
102
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowViewBean.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.view.registration;
10

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

  
16
import org.springframework.security.core.GrantedAuthority;
17
import org.vaadin.viritin.fields.LazyComboBox;
18

  
19
import com.vaadin.navigator.View;
20
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
21
import com.vaadin.server.FontAwesome;
22
import com.vaadin.server.GenericFontIcon;
23
import com.vaadin.server.Page;
24
import com.vaadin.spring.annotation.SpringView;
25
import com.vaadin.ui.AbstractLayout;
26
import com.vaadin.ui.Alignment;
27
import com.vaadin.ui.Button;
28
import com.vaadin.ui.Component;
29
import com.vaadin.ui.CssLayout;
30
import com.vaadin.ui.GridLayout;
31
import com.vaadin.ui.HorizontalLayout;
32
import com.vaadin.ui.Label;
33
import com.vaadin.ui.Notification;
34
import com.vaadin.ui.Panel;
35
import com.vaadin.ui.TabSheet;
36
import com.vaadin.ui.TabSheet.Tab;
37
import com.vaadin.ui.UI;
38
import com.vaadin.ui.VerticalLayout;
39
import com.vaadin.ui.Window;
40
import com.vaadin.ui.themes.ValoTheme;
41

  
42
import eu.etaxonomy.cdm.model.name.TaxonName;
43
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
44
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
45
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup.TypeDesignationWorkingSetButton;
46
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStateLabel;
47
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
48
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
49
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
50
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
51
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
52
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
53
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
54
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
55
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
56
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
57
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
58
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
59
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
60
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
61
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
62
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
63

  
64
/**
65
 * @author a.kohlbecker
66
 * @since Mar 2, 2017
67
 *
68
 */
69
@SpringView(name=RegistrationWorkflowViewBean.NAME)
70
public class RegistrationWorkflowViewBean extends AbstractPageView<RegistrationWorkflowPresenter>
71
    implements RegistrationWorkflowView, View, AccessRestrictedView {
72

  
73
    public static final String DOM_ID_WORKINGSET = "workingset";
74

  
75
    private static final long serialVersionUID = -213040114015958970L;
76

  
77
    public static final String NAME = "workflow";
78

  
79
    private static final boolean REG_ITEM_AS_BUTTON_GROUP = true;
80

  
81
    public RegistrationType regType = null;
82

  
83
    private List<CssLayout> registrations = new ArrayList<>();
84

  
85
    private String headerText = "Registration Workingset Editor";
86
    private String subheaderText = "";
87

  
88
    private boolean addNameAndTypeEditButtons = false;
89

  
90
    private Integer citationID;
91

  
92
    private Button addNewNameRegistrationButton;
93

  
94
    private LazyComboBox<TaxonName> existingNameCombobox;
95

  
96
    private GridLayout registrationsGrid;
97

  
98
    private Button addExistingNameButton;
99

  
100
    private RegistrationItem workingsetHeader;
101

  
102
    private Panel registrationListPanel;
103

  
104
    public RegistrationWorkflowViewBean() {
105
        super();
106
    }
107

  
108

  
109
    /**
110
     * {@inheritDoc}
111
     */
112
    @Override
113
    protected void initContent() {
114
        getLayout().setId(NAME);
115
        updateHeader();
116
        // all content is added in createRegistrationsList()
117
    }
118

  
119

  
120
    /**
121
     * {@inheritDoc}
122
     */
123
    @Override
124
    public void enter(ViewChangeEvent event) {
125
        if(event.getParameters() != null){
126
            this.citationID = Integer.valueOf(event.getParameters());
127

  
128
            getPresenter().handleViewEntered();
129
        }
130
    }
131

  
132
    /**
133
     * {@inheritDoc}
134
     */
135
    @Override
136
    public void setWorkingset(RegistrationWorkingSet workingset) {
137
        if(workingsetHeader != null){
138
            getLayout().removeComponent(workingsetHeader);
139
            getLayout().removeComponent(registrationListPanel);
140
        }
141

  
142
        registrationListPanel = createRegistrationsList(workingset);
143
        registrationListPanel.setStyleName("registration-list");
144
        registrationListPanel.setCaption("Registrations");
145

  
146
        workingsetHeader = new RegistrationItem(workingset, this);
147
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
148
            workingsetHeader.getSubmitterLabel().setVisible(true);
149
        }
150
        addContentComponent(workingsetHeader, null);
151
        addContentComponent(registrationListPanel, 1.0f);
152

  
153
    }
154

  
155
    /**
156
     * {@inheritDoc}
157
     */
158
    @Override
159
    public void addBlockingRegistration(RegistrationDTO blocking) {
160
        if(registrations == null) {
161
            throw new RuntimeException("A Workingset must be present prior adding blocking registrations.");
162
        }
163
        // add the blocking registration
164

  
165
    }
166

  
167
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
168

  
169
        if(namesTypesPanel == null){
170
            namesTypesPanel = new CssLayout();
171
        }
172
        Component citationComponent = new CssLayout(); // new Label(workingset.getCitation());
173
        Component curationComponent = new CssLayout(); // new Label("Curation in progress ...")
174
        Component releaseComponent = new CssLayout(); // new Label("Not yet published")
175

  
176
        GenericFontIcon tabIcon = new GenericFontIcon("IcoMoon", 0xe900);
177
        TabSheet tabsheet = new TabSheet();
178
        // tabsheet.addStyleName(ValoTheme.TABSHEET_FRAMED);
179
        //tabsheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
180
        tabsheet.addStyleName("workflow-tabsheet");
181

  
182
        Tab pubDetailsTab = tabsheet.addTab(citationComponent, WorkflowStep.PUBLICATION_DETAILS.getRepresentation(), tabIcon);
183
        Tab namesTypesTab = tabsheet.addTab(namesTypesPanel, WorkflowStep.NAMES_N_TYPES.getRepresentation(), tabIcon);
184
        Tab curationTab = tabsheet.addTab(curationComponent, WorkflowStep.CURATION.getRepresentation(), tabIcon);
185
        Tab awaitingPubTab = tabsheet.addTab(releaseComponent, WorkflowStep.AWAITING_PUBLICATION.getRepresentation(), tabIcon);
186

  
187
        pubDetailsTab.setStyleName("bg-status-" + WorkflowStep.PUBLICATION_DETAILS.name());
188
        namesTypesTab.setStyleName("bg-status-" + WorkflowStep.NAMES_N_TYPES.name());
189
        curationTab.setStyleName("bg-status-" + WorkflowStep.CURATION.name());
190
        awaitingPubTab.setStyleName("bg-status-" + WorkflowStep.AWAITING_PUBLICATION.name());
191

  
192
        return tabsheet;
193
    }
194

  
195
    /**
196
     * @param workingset
197
     * @return
198
     */
199
    public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
200

  
201
        registrationsGrid = new GridLayout(3, 1);
202
        registrationsGrid.setWidth("100%");
203
        // allow vertical scrolling:
204
        registrationsGrid.setHeightUndefined();
205

  
206
        //registrationsGrid.setColumnExpandRatio(0, 0.1f);
207
        registrationsGrid.setColumnExpandRatio(1, 1f);
208

  
209
        int row = 0;
210
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
211
            putRegistrationListComponent(registrationsGrid, row++, dto);
212
        }
213

  
214
        Label addRegistrationLabel_1 = new Label("Add a new registration for a");
215
        Label addRegistrationLabel_2 = new Label("or an");
216

  
217
        addNewNameRegistrationButton = new Button("new name");
218
        addNewNameRegistrationButton.setDescription("A name which is newly published in this publication.");
219
        addNewNameRegistrationButton.addClickListener(
220
                e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.ADD, addNewNameRegistrationButton))
221
                );
222

  
223
        addExistingNameButton = new Button("existing name:");
224
        addExistingNameButton.setDescription("A name which was previously published in a earlier publication.");
225
        addExistingNameButton.setEnabled(false);
226
        addExistingNameButton.addClickListener(
227
                e -> eventBus.publishEvent(new RegistrationWorkflowEvent(citationID, RegistrationWorkflowEvent.Action.start))
228
                );
229

  
230
        existingNameCombobox = new LazyComboBox<TaxonName>(TaxonName.class);
231
        existingNameCombobox.addValueChangeListener(
232
                e -> addExistingNameButton.setEnabled(e.getProperty().getValue() != null)
233
                );
234

  
235
        HorizontalLayout buttonContainer = new HorizontalLayout(addRegistrationLabel_1, addNewNameRegistrationButton, addRegistrationLabel_2, addExistingNameButton, existingNameCombobox);
236
        buttonContainer.setSpacing(true);
237
//        buttonContainer.setWidth(100, Unit.PERCENTAGE);
238
        buttonContainer.setComponentAlignment(addRegistrationLabel_1, Alignment.MIDDLE_LEFT);
239
        buttonContainer.setComponentAlignment(addRegistrationLabel_2, Alignment.MIDDLE_LEFT);
240
        registrationsGrid.addComponent(buttonContainer, 0, row, 2, row);
241
        registrationsGrid.setComponentAlignment(buttonContainer, Alignment.MIDDLE_RIGHT);
242

  
243
        Panel namesTypesPanel = new Panel(registrationsGrid);
244
        namesTypesPanel.setSizeFull();
245
        return namesTypesPanel;
246
    }
247

  
248

  
249
    /**
250
     * @param grid
251
     * @param row If null, the new row will be inserted as last registration item, that is before the button row.
252
     * @param dto
253
     */
254
    protected void putRegistrationListComponent(GridLayout grid, int row, RegistrationDTO dto) {
255

  
256
        grid.setRows(grid.getRows() + 1);
257

  
258
        CssLayout buttonGroup = new CssLayout();
259
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
260

  
261
        Button messageButton = new Button(FontAwesome.COMMENT);
262
        messageButton.setStyleName(ValoTheme.BUTTON_TINY); //  + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
263
        if(dto.getMessages().isEmpty()){
264
            messageButton.setEnabled(false);
265
        } else {
266
            messageButton.addClickListener(e -> eventBus.publishEvent(
267
                    new ShowDetailsEvent<RegistrationDTO, Integer>(
268
                        e,
269
                        RegistrationDTO.class,
270
                        dto.getId(),
271
                        "messages"
272
                        )
273
                    )
274
                );
275
        }
276
        messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
277
        messageButton.setCaptionAsHtml(true);
278
        buttonGroup.addComponent(messageButton);
279

  
280
        RegistrationStateLabel stateLabel = new RegistrationStateLabel().update(dto.getStatus());
281

  
282

  
283
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
284
            Button editRegistrationButton = new Button(FontAwesome.COG);
285
            editRegistrationButton.setStyleName(ValoTheme.BUTTON_TINY);
286
            editRegistrationButton.setDescription("Edit registration");
287
            editRegistrationButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
288
                AbstractEditorAction.Action.EDIT,
289
                dto.getId(),
290
                null,
291
                this
292
                )));
293
            buttonGroup.addComponent(editRegistrationButton);
294
        }
295

  
296
        if(addNameAndTypeEditButtons ){
297
            Button editNameButton = new Button(FontAwesome.TAG);
298
            editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
299
            editNameButton.setDescription("Edit name");
300
            if(dto.getName() != null){
301
                editNameButton.addClickListener(e -> {
302
                        Integer nameId = dto.getName().getId();
303
                        getEventBus().publishEvent(new TaxonNameEditorAction(
304
                            AbstractEditorAction.Action.EDIT,
305
                            nameId
306
                            )
307
                        );
308
                    });
309
            } else {
310
                editNameButton.setEnabled(false);
311
            }
312

  
313
            Button editTypesButton = new Button(FontAwesome.LEAF);
314
            editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
315
            editTypesButton.setDescription("Edit type designations");
316
            if(dto.getOrderdTypeDesignationWorkingSets() != null && !dto.getOrderdTypeDesignationWorkingSets().isEmpty()){
317
//                editTypesButton.addClickListener(e -> {
318
//                    int regId = dto.getId();
319
//                        getEventBus().publishEvent(new TypeDesignationSetEditorAction(
320
//                            AbstractEditorAction.Action.EDIT,
321
//                            regId
322
//                            )
323
//                        );
324
//                    });
325
            } else {
326
                editTypesButton.setEnabled(false);
327
            }
328
            buttonGroup.addComponents(editNameButton, editTypesButton);
329
        }
330

  
331
        Component regItem;
332
        if(REG_ITEM_AS_BUTTON_GROUP){
333
            RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
334

  
335
            if(editButtonGroup.getNameButton() != null){
336
                editButtonGroup.getNameButton().getButton().addClickListener(e -> {
337
                    Integer nameId = editButtonGroup.getNameButton().getId();
338
                    getEventBus().publishEvent(new TaxonNameEditorAction(
339
                        AbstractEditorAction.Action.EDIT,
340
                        nameId,
341
                        null, //e.getButton(), the listener method expects this to be null
342
                        this
343
                        )
344
                    );
345
                });
346
            }
347

  
348
            for(TypeDesignationWorkingSetButton workingsetButton : editButtonGroup.getTypeDesignationButtons()){
349
                workingsetButton.getButton().addClickListener(e -> {
350
                    Integer typeDesignationWorkingsetId = workingsetButton.getId();
351
                    TypeDesignationWorkingSetType workingsetType = workingsetButton.getType();
352
                    Integer registrationEntityID = dto.getId();
353
                    getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
354
                            AbstractEditorAction.Action.EDIT,
355
                            typeDesignationWorkingsetId,
356
                            workingsetType,
357
                            registrationEntityID,
358
                            null, //e.getButton(), the listener method expects this to be null
359
                            this
360
                            )
361
                        );
362
                });
363
            }
364

  
365
            editButtonGroup.getAddTypeDesignationButton().addClickListener(
366
                    e -> chooseNewTypeRegistrationWorkingset(dto.getId())
367
                    );
368
            regItem = editButtonGroup;
369
        } else {
370
            regItem = new Label(dto.getSummary());
371
        }
372

  
373
        grid.addComponent(stateLabel, 0, row);
374
        grid.setComponentAlignment(stateLabel, Alignment.TOP_LEFT);
375
        grid.addComponent(regItem, 1, row);
376
        grid.addComponent(buttonGroup, 2, row);
377
        grid.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
378
    }
379

  
380
    /**
381
     * @param button
382
     * @param registrationEntityId
383
     *
384
     */
385
    @Override
386
    public void chooseNewTypeRegistrationWorkingset(Integer registrationEntityId) {
387

  
388
        Window typeDesignationTypeCooser = new Window();
389
        typeDesignationTypeCooser.setModal(true);
390
        typeDesignationTypeCooser.setResizable(false);
391
        typeDesignationTypeCooser.setCaption("Add new type designation");
392
        Label label = new Label("Please select kind of type designation to be created.");
393
        Button newSpecimenTypeDesignationButton = new Button("Specimen type designation",
394
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
395
        Button newNameTypeDesignationButton = new Button("Name type designation",
396
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
397
        newNameTypeDesignationButton.setEnabled(false);
398

  
399
        VerticalLayout layout = new VerticalLayout(label, newSpecimenTypeDesignationButton, newNameTypeDesignationButton);
400
        layout.setMargin(true);
401
        layout.setSpacing(true);
402
        layout.setComponentAlignment(newSpecimenTypeDesignationButton, Alignment.MIDDLE_CENTER);
403
        layout.setComponentAlignment(newNameTypeDesignationButton, Alignment.MIDDLE_CENTER);
404
        typeDesignationTypeCooser.setContent(layout);
405
        UI.getCurrent().addWindow(typeDesignationTypeCooser);
406
    }
407

  
408
    /**
409
     * @param button
410
     *
411
     */
412
    protected void addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType newWorkingsetType, Integer registrationEntityId, Window typeDesignationTypeCooser) {
413
        UI.getCurrent().removeWindow(typeDesignationTypeCooser);
414
        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
415
                AbstractEditorAction.Action.ADD,
416
                newWorkingsetType,
417
                registrationEntityId,
418
                null,
419
                this
420
                ));
421
    }
422

  
423

  
424
    /**
425
    *
426
    */
427
   private void addBulletWorkflowName() {
428
       WorkflowSteps steps = new WorkflowSteps();
429
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
430
               e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
431
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
432
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
433
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
434
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
435
       getWorkflow().addComponent(steps);
436
   }
437

  
438
   /**
439
   *
440
   */
441
  private void addBulletWorkflowTypification() {
442
      WorkflowSteps steps = new WorkflowSteps();
443
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
444
              e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
445
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
446
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
447
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
448
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
449
      getWorkflow().addComponent(steps);
450
  }
451

  
452
    /**
453
     * {@inheritDoc}
454
     */
455
    @Override
456
    public void openReferenceEditor(UUID referenceUuid) {
457
        // TODO Auto-generated method stub
458

  
459
    }
460

  
461
    /**
462
     * {@inheritDoc}
463
     */
464
    @Override
465
    public void openNameEditor(UUID nameUuid) {
466
        // TODO Auto-generated method stub
467

  
468
    }
469

  
470
    /**
471
     * {@inheritDoc}
472
     */
473
    @Override
474
    protected String getHeaderText() {
475
        return headerText;
476
    }
477

  
478
    /**
479
     * {@inheritDoc}
480
     */
481
    @Override
482
    public void setHeaderText(String text) {
483
        this.headerText = text;
484
        updateHeader();
485

  
486
    }
487

  
488
    /**
489
     * @return the subheaderText
490
     */
491
    public String getSubheaderText() {
492
        return subheaderText;
493
    }
494

  
495
    /**
496
     * {@inheritDoc}
497
     */
498
    @Override
499
    public void setSubheaderText(String text) {
500
        subheaderText = text;
501
        updateHeader();
502
    }
503

  
504
    /**
505
     * {@inheritDoc}
506
     */
507
    @Override
508
    protected String getSubHeaderText() {
509
        return subheaderText;
510
    }
511

  
512
    /**
513
     * {@inheritDoc}
514
     */
515
    @Override
516
    public AbstractLayout getWorkflow() {
517
        return getLayout();
518
    }
519

  
520
    /**
521
     * {@inheritDoc}
522
     */
523
    @Override
524
    public void openDetailsPopup(String caption, List<String> messages) {
525
        StringBuffer sb = new StringBuffer();
526
        sb.append("<div class=\"details-popup-content\">");
527
        messages.forEach(s -> sb.append(s).append("</br>"));
528
        sb.append("</div>");
529
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
530
    }
531

  
532
    /**
533
     * {@inheritDoc}
534
     */
535
    @Override
536
    public boolean allowAnonymousAccess() {
537
        return false;
538
    }
539

  
540
    /**
541
     * {@inheritDoc}
542
     */
543
    @Override
544
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
545
        return null;
546
    }
547

  
548
    /**
549
     * @return the addNewNameRegistrationButton
550
     */
551
    @Override
552
    public Button getAddNewNameRegistrationButton() {
553
        return addNewNameRegistrationButton;
554
    }
555

  
556
    @Override
557
    public Button getAddExistingNameRegistrationButton() {
558
        return addExistingNameButton;
559
    }
560

  
561
    @Override
562
    public LazyComboBox<TaxonName> getAddExistingNameCombobox() {
563
        return existingNameCombobox;
564
    }
565

  
566
    /**
567
     * @return the citationID
568
     */
569
    @Override
570
    public Integer getCitationID() {
571
        return citationID;
572
    }
573

  
574

  
575
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.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.view.registration;
10

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

  
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.context.event.EventListener;
16
import org.springframework.security.core.Authentication;
17

  
18
import com.vaadin.server.SystemError;
19
import com.vaadin.spring.annotation.SpringComponent;
20
import com.vaadin.spring.annotation.ViewScope;
21

  
22
import eu.etaxonomy.cdm.api.service.INameService;
23
import eu.etaxonomy.cdm.api.service.IRegistrationService;
24
import eu.etaxonomy.cdm.model.common.User;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.name.Registration;
27
import eu.etaxonomy.cdm.model.name.TaxonName;
28
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
29
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
32
import eu.etaxonomy.cdm.service.CdmStore;
33
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
34
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
35
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
36
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
37
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
38
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
39
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
40
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
41
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
42
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
43
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
44
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
45
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
46
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
47
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
48
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
49
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
50
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
51

  
52
/**
53
 * @author a.kohlbecker
54
 * @since Mar 3, 2017
55
 *
56
 */
57
@SpringComponent
58
@ViewScope
59
public class RegistrationWorkingsetPresenter extends AbstractPresenter<RegistrationWorkingsetView> {
60

  
61
    private static final long serialVersionUID = 1L;
62

  
63
    @Autowired
64
    private IRegistrationWorkingSetService workingSetService;
65

  
66
    /**
67
     * @return the workingSetService
68
     */
69
    public IRegistrationWorkingSetService getWorkingSetService() {
70
        ensureBoundConversation();
71
        return workingSetService;
72
    }
73

  
74
    private RegistrationWorkingSet workingset;
75

  
76
    private TaxonName newTaxonNameForRegistration = null;
77

  
78
    private RegistrationDTO newRegistrationDTOWithExistingName;
79

  
80

  
81
    /**
82
     *
83
     */
84
    public RegistrationWorkingsetPresenter() {
85
    }
86

  
87

  
88
    /**
89
     * Always create a new Store
90
     *
91
     * @return
92
     */
93
    protected CdmStore<Registration, IRegistrationService> getRegistrationStore(){
94
        return new CdmStore<Registration, IRegistrationService>(getRepo(), getRepo().getRegistrationService());
95
    }
96

  
97
    /**
98
     * Always create a new Store
99
     *
100
     * @return
101
     */
102
    protected CdmStore<TaxonName, INameService> getTaxonNameStore(){
103
        return new  CdmStore<TaxonName, INameService>(getRepo(), getRepo().getNameService());
104
    }
105

  
106

  
107
    /**
108
     * @param taxonNameId
109
     * @return
110
     */
111
    protected Registration createNewRegistrationForName(Integer taxonNameId) {
112
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
        // move into RegistrationWorkflowStateMachine
114
        long identifier = System.currentTimeMillis();
115
        Registration reg = Registration.NewInstance(
116
                "http://phycobank.org/" + identifier,
117
                "" + identifier,
118
                taxonNameId != null ? getRepo().getNameService().find(taxonNameId) : null,
119
                null);
120
        Authentication authentication = currentSecurityContext().getAuthentication();
121
        reg.setSubmitter((User)authentication.getPrincipal());
122
        EntityChangeEvent event = getRegistrationStore().saveBean(reg);
123
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
        return getRepo().getRegistrationService().find(event.getEntityId());
125
    }
126

  
127

  
128
    /**
129
     *
130
     */
131
    protected void refreshView() {
132
        getConversationHolder().getSession().clear();
133
        presentWorkingSet(workingset.getCitationId());
134
    }
135

  
136

  
137
    /**
138
     * {@inheritDoc}
139
     */
140
    @Override
141
    public void handleViewEntered() {
142

  
143
        super.handleViewEntered();
144

  
145
        presentWorkingSet(getView().getCitationID());
146

  
147
        CdmFilterablePagingProvider<TaxonName> pagingProvider = new CdmFilterablePagingProvider<TaxonName>(
148
                getRepo().getNameService(), this);
149
        CdmTitleCacheCaptionGenerator<TaxonName> titleCacheGenrator = new CdmTitleCacheCaptionGenerator<TaxonName>();
150
        getView().getAddExistingNameCombobox().setCaptionGenerator(titleCacheGenrator);
151
        getView().getAddExistingNameCombobox().loadFrom(pagingProvider, pagingProvider, pagingProvider.getPageSize());
152
    }
153

  
154
    /**
155
     * Loads the WorkingSet from the data base and passes it to the view.
156
     *
157
     * @param registrationID
158
     */
159
    private void presentWorkingSet(Integer referenceID) {
160
        try {
161
            workingset = getWorkingSetService().loadWorkingSetByReferenceID(referenceID);
162
        } catch (RegistrationValidationException error) {
163
            getView().getWorkflow().setComponentError(new SystemError(error));
164
        }
165
        if(workingset == null || workingset.getCitationId() == null){
166
            Reference citation = getRepo().getReferenceService().find(referenceID);
167
            workingset = new RegistrationWorkingSet(citation);
168
        }
169
        // getView().setHeaderText("Registrations for " + workingset.getCitation());
170
        getView().setWorkingset(workingset);
171
    }
172

  
173
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD && #event.sourceComponent == null")
174
    public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
175
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
176
        popup.loadInEditor(null);
177
    }
178

  
179
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
180
    public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
181
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
182
        popup.withDeleteButton(true);
183
        popup.loadInEditor(event.getEntityId());
184
    }
185

  
186
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
187
    public void onRegistrationEditorAction(RegistrationEditorAction event) {
188
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class);
189
        popup.loadInEditor(event.getEntityId());
190
    }
191

  
192
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
193
    public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
194

  
195
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
196
        popup.withDeleteButton(true);
197
        // disable NomReferenceCombobox:
198
        // the in the registration application inReferences should only edited centrally
199
        popup.getNomReferenceCombobox().setEnabled(false);
200
        popup.loadInEditor(event.getEntityId());
201
    }
202

  
203
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD")
204
    public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
205

  
206
        newTaxonNameForRegistration = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
207
        newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
208
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration);
209
        newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
210
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
211
        popup.withDeleteButton(true);
212
        popup.loadInEditor(newTaxonNameForRegistration.getId());
213
        // disable NomReferenceCombobox:
214
        // the in the registration application inReferences should only edited centrally
215
        popup.getNomReferenceCombobox().setEnabled(false);
216
    }
217

  
218
    /**
219
     * Creates a new <code>Registration</code> for a new name that has just been edited
220
     * using the <code>TaxonNamePopupEditor</code>. The new name was previously created
221
     * in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
222
     * and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
223
     * (<code>Reason.CANCEL</code>).
224
     *
225
     *
226
     * @param event
227
     * @throws RegistrationValidationException
228
     */
229
    @EventListener
230
    public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
231
        if(event.getPopup() instanceof TaxonNamePopupEditor){
232
            if(newTaxonNameForRegistration != null && event.getReason().equals(Reason.SAVE)){
233
                int taxonNameId = newTaxonNameForRegistration.getId();
234
                Registration reg = createNewRegistrationForName(taxonNameId);
235
                workingset.add(reg);
236
                refreshView();
237
            } else if(event.getReason().equals(Reason.CANCEL)){
238
                // clean up
239
                getTaxonNameStore().deleteBean(newTaxonNameForRegistration);
240
            }
241
            newTaxonNameForRegistration = null;
242
        }
243
    }
244

  
245

  
246
    /**
247
     * Creates a new Registration for an exiting (previously published name).
248
     *
249
     * @param event
250
     * @throws RegistrationValidationException
251
     */
252
    @EventListener(condition = "#event.action == T(eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent.Action).start")
253
    public void onRegistrationWorkflowEventActionStart(RegistrationWorkflowEvent event) throws RegistrationValidationException {
254

  
255
        getView().getAddExistingNameCombobox().commit();
256
        TaxonName typifiedName = getView().getAddExistingNameCombobox().getValue();
257
        if(typifiedName != null){
258
            Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
259
            Reference citation = getRepo().getReferenceService().find(workingset.getCitationId());
260
            newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
261
            workingset.add(newRegistrationDTOWithExistingName);
262
            // tell the view to update the workingset
263
            getView().setWorkingset(workingset);
264
            getView().getAddExistingNameRegistrationButton().setEnabled(false);
265
            getView().getAddExistingNameRegistrationButton().setDescription("You first need to add a type designation to the previously created registration.");
266
        } else {
267
            logger.error("Seletced name is NULL");
268
        }
269

  
270
    }
271

  
272
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
273
    public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event) {
274

  
275
            if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
276
                SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
277
                popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getEntityId()));
278
            } else {
279
                // TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
280
                // FIXME implement NameTypeDesignationWorkingsetPopupEditor
281
            }
282
    }
283

  
284
    @EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD && #event.sourceComponent == null")
285
    public void onAddNewTypeDesignationWorkingset(TypeDesignationWorkingsetEditorAction event) {
286

  
287
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
288
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
289
            TypeDesignationWorkingsetEditorIdSet identifierSet;
290
            Integer typifiedNameId;
291
            if(newRegistrationDTOWithExistingName != null){
292
                typifiedNameId = newRegistrationDTOWithExistingName.getTypifiedName().getId();
293
            } else {
294
                typifiedNameId = workingset.getRegistrationDTO(event.getRegistrationId())
295
                        .get()
296
                        .getTypifiedName()
297
                        .getId();
298
            }
299
            identifierSet = new TypeDesignationWorkingsetEditorIdSet(
300
                    event.getRegistrationId(),
301
                    getView().getCitationID(),
302
                    typifiedNameId
303
                    );
304
            popup.loadInEditor(identifierSet
305
                 );
306
            popup.withDeleteButton(true);
307
        } else {
308
            // TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
309
            // FIXME implement NameTypeDesignationWorkingsetPopupEditor
310
        }
311
    }
312

  
313
    /**
314
     * Performs final actions after a TypeDesignationEditor which has been
315
     * opened to add a TypeDesignation to a Registration object which was
316
     * created for an previously published name. Prior adding a typedesignation,
317
     * the according Registration object is dangling, that has no association to
318
     * any entity denoting an nomenclatural act which has a reference to a
319
     * publication. This means that the registration object is not in the
320
     * working set.
321
     *
322
     *
323
     * @param event
324
     * @throws RegistrationValidationException
325
     */
326
    @EventListener
327
    public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
328
        if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
329
            if(event.getReason().equals(Reason.SAVE)){
330
                 refreshView();
331
            } else if(event.getReason().equals(Reason.CANCEL)){
332
                // clean up
333
                if(newRegistrationDTOWithExistingName != null){
334
                    getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration());
335
                }
336
            }
337
            // set newRegistrationDTOWithExistingName NULL in any case
338
            newRegistrationDTOWithExistingName = null;
339
        }
340
    }
341

  
342

  
343
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
344
    public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
345
        List<String> messages = new ArrayList<>();
346
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
347
            dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
348
        }
349
        if(event.getProperty().equals("messages")){
350
            getView().openDetailsPopup("Messages", messages);
351
        }
352
    }
353

  
354
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
355
    public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
356
        RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
357
        if(event.getProperty().equals("messages")){
358
            if(getView() != null){
359
                getView().openDetailsPopup("Messages", regDto.getMessages());
360
            }
361
        }
362
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff