2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.view
.registration
;
11 import java
.util
.EnumSet
;
12 import java
.util
.UUID
;
14 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
15 import org
.vaadin
.spring
.events
.EventScope
;
16 import org
.vaadin
.spring
.events
.annotation
.EventBusListenerMethod
;
17 import org
.vaadin
.viritin
.fields
.LazyComboBox
;
19 import com
.vaadin
.server
.SystemError
;
20 import com
.vaadin
.server
.UserError
;
21 import com
.vaadin
.spring
.annotation
.SpringComponent
;
22 import com
.vaadin
.spring
.annotation
.ViewScope
;
24 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
25 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RegistrationDTO
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
28 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.Restriction
;
29 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.Restriction
.Operator
;
30 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CRUD
;
31 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
32 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProviderFactory
;
33 import eu
.etaxonomy
.cdm
.vaadin
.event
.EditorActionTypeFilter
;
34 import eu
.etaxonomy
.cdm
.vaadin
.event
.ReferenceEditorAction
;
35 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegistrationEditorAction
;
36 import eu
.etaxonomy
.cdm
.vaadin
.ui
.RegistrationUIDefaults
;
37 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
38 import eu
.etaxonomy
.cdm
.vaadin
.view
.reference
.ReferencePopupEditor
;
39 import eu
.etaxonomy
.vaadin
.mvp
.AbstractEditorPresenter
;
40 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
41 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
;
42 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
.Reason
;
45 * @author a.kohlbecker
51 public class StartRegistrationPresenter
extends AbstractEditorPresenter
<RegistrationDTO
, StartRegistrationView
> {
53 private static final long serialVersionUID
= 2283189121081612574L;
55 private ReferencePopupEditor newReferencePopup
;
57 private Reference newReference
;
59 private boolean registrationInProgress
;
62 protected CdmFilterablePagingProviderFactory pagingProviderFactory
;
64 public StartRegistrationPresenter (){
73 public void handleViewEntered() {
75 super.handleViewEntered();
77 CdmFilterablePagingProvider
<Reference
, Reference
> pagingProvider
= pagingProviderFactory
.referencePagingProvider();
78 CdmTitleCacheCaptionGenerator
<Reference
> titleCacheGenrator
= new CdmTitleCacheCaptionGenerator
<Reference
>();
79 pagingProvider
.addRestriction(new Restriction("type", Operator
.AND_NOT
, null, ReferenceType
.Section
, ReferenceType
.Journal
, ReferenceType
.PrintSeries
));
80 getView().getReferenceCombobox().setCaptionGenerator(titleCacheGenrator
);
81 getView().getReferenceCombobox().loadFrom(pagingProvider
, pagingProvider
, pagingProvider
.getPageSize());
88 public void handleViewExit() {
89 if(!registrationInProgress
&& newReference
!= null){
90 logger
.info("Deleting newly created Reference due to canceled registration");
91 getRepo().getReferenceService().delete(newReference
);
93 super.handleViewExit();
97 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
98 public void onReferenceEditorActionAdd(ReferenceEditorAction event
) {
100 if(getView() == null || getView().getNewPublicationButton() != event
.getSource()){
104 newReferencePopup
= openPopupEditor(ReferencePopupEditor
.class, event
);
105 EnumSet
<ReferenceType
> refTypes
= RegistrationUIDefaults
.PRINTPUB_REFERENCE_TYPES
.clone();
106 refTypes
.remove(ReferenceType
.Section
);
107 newReferencePopup
.withReferenceTypes(refTypes
);
109 newReferencePopup
.grantToCurrentUser(EnumSet
.of(CRUD
.UPDATE
, CRUD
.DELETE
));
110 newReferencePopup
.withDeleteButton(true);
111 newReferencePopup
.loadInEditor(null);
112 newReferencePopup
.getTypeSelect().setValue(ReferenceType
.Article
);
115 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Remove
.class)
116 public void onReferenceEditorActionRemove(ReferenceEditorAction event
) {
118 if(getView().getRemoveNewPublicationButton() != event
.getSource()){
121 DeleteResult result
= getRepo().getReferenceService().delete(newReference
);
124 for(Exception e
: result
.getExceptions()){
125 message
+= e
.getMessage() + "\n" + e
.getStackTrace().toString() + "\n";
127 getView().getRemoveNewPublicationButton().setComponentError(new SystemError(message
));
130 getView().getReferenceCombobox().setEnabled(false);
132 getView().getRemoveNewPublicationButton().setVisible(false);
134 getView().getNewPublicationButton().setVisible(true);
135 getView().getNewPublicationLabel().setCaption(null);
136 getView().getNewPublicationLabel().setVisible(false);
139 @EventBusListenerMethod
140 public void onDoneWithPopupEvent(DoneWithPopupEvent event
){
142 if(event
.getPopup() == newReferencePopup
){
143 if(event
.getReason() == Reason
.SAVE
){
145 newReference
= newReferencePopup
.getBean();
147 // TODO the bean contained in the popup editor is not yet updated at this point.
148 // so re reload it using the uuid since new beans will not have an Id at this point.
149 newReference
= getRepo().getReferenceService().find(newReference
.getUuid());
151 getView().getReferenceCombobox().setValue(null); // deselect
152 getView().getReferenceCombobox().setEnabled(false);
154 getView().getContinueButton().setEnabled(true);
156 getView().getNewPublicationButton().setVisible(false);
158 getView().getRemoveNewPublicationButton().setVisible(true);
159 getView().getNewPublicationLabel().setCaption(newReference
.getTitleCache());
160 getView().getNewPublicationLabel().setVisible(true);
163 newReferencePopup
= null;
167 @SuppressWarnings("null")
168 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
169 public void onRegistrationEditorActionAdd(RegistrationEditorAction event
) {
171 if(getView().getContinueButton() != event
.getSource()){
175 UUID referenceUuid
= null;
176 LazyComboBox
<Reference
> referenceCombobox
= getView().getReferenceCombobox();
177 referenceCombobox
.commit();
178 if(newReference
!= null){
179 referenceUuid
= newReference
.getUuid();
180 // } else if(referenceCombobox.getValue() != null) {
181 } else if ( event
.getEntityUuid() != null) { // HACKED, see view implementation
182 referenceUuid
= event
.getEntityUuid();
184 if(referenceUuid
== null){
185 getView().getContinueButton().setComponentError(new UserError("Can't continue. No Reference is chosen."));
186 getView().getContinueButton().setEnabled(false);
188 registrationInProgress
= true;
189 viewEventBus
.publish(EventScope
.UI
, this, new NavigationEvent(RegistrationWorksetViewBean
.NAME
, referenceUuid
.toString()));
197 protected RegistrationDTO
loadBeanById(Object identifier
) {
206 protected void saveBean(RegistrationDTO bean
) {
214 protected void deleteBean(RegistrationDTO bean
) {