ref #6169 visualization of RegistrationWorkingSets in the workflow view
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / presenter / 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.presenter.registration;
10
11 import org.apache.log4j.Logger;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.context.event.EventListener;
14
15 import com.vaadin.server.SystemError;
16 import com.vaadin.spring.annotation.SpringComponent;
17 import com.vaadin.spring.annotation.ViewScope;
18
19 import eu.etaxonomy.cdm.mock.Registration;
20 import eu.etaxonomy.cdm.mock.RegistrationService;
21 import eu.etaxonomy.cdm.model.name.Rank;
22 import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
23 import eu.etaxonomy.cdm.vaadin.event.ReferenceEvent;
24 import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
25 import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
26 import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowView;
27 import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
28
29 /**
30 * @author a.kohlbecker
31 * @since Mar 3, 2017
32 *
33 */
34 @SpringComponent
35 @ViewScope
36 public class RegistrationWorkflowPresenter extends AbstractPresenter<RegistrationWorkflowView> {
37
38
39 @Autowired
40 private RegistrationService serviceMock;
41
42 private RegistrationWorkingSet workingset;
43
44 /**
45 *
46 */
47 public RegistrationWorkflowPresenter() {
48 }
49
50 @EventListener
51 protected void onRegistrationStartEvent(RegistrationWorkflowEvent event){
52
53 if(workingset != null){
54 Logger.getLogger(RegistrationWorkflowPresenter.class).warn("Cant start a new workflow over an existing one.");
55 return;
56 }
57
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 }
69 } else {
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());
76 }
77 if(workingset != null){
78 getView().setWorkingset(workingset);
79 //TODO add Blocking registrations to view
80 }
81 }
82
83 // @EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EventType).ADD")
84 // public void onReferenceAddEvent(ReferenceEvent event) {
85 // getView().openReferenceEditor(null);
86 // }
87
88 @EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EventType).EDIT")
89 public void onReferenceEditEvent(ReferenceEvent event) {
90 getView().openReferenceEditor(null);
91 }
92
93 }