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.EnumSet;
|
12
|
import java.util.UUID;
|
13
|
|
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;
|
18
|
|
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;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
25
|
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
|
26
|
import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
29
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
|
30
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction.Operator;
|
31
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
32
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
33
|
import eu.etaxonomy.cdm.ref.TypedEntityReference;
|
34
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProviderFactory;
|
35
|
import eu.etaxonomy.cdm.service.TypifiedEntityFilterablePagingProvider;
|
36
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
|
37
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
38
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
39
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
40
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
41
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
42
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
43
|
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
|
44
|
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
|
45
|
|
46
|
/**
|
47
|
* @author a.kohlbecker
|
48
|
* @since Jul 11, 2017
|
49
|
*
|
50
|
*/
|
51
|
@SpringComponent
|
52
|
@ViewScope
|
53
|
public class StartRegistrationPresenter extends AbstractEditorPresenter<RegistrationDTO, StartRegistrationView> {
|
54
|
|
55
|
private static final long serialVersionUID = 2283189121081612574L;
|
56
|
|
57
|
private ReferencePopupEditor newReferencePopup;
|
58
|
|
59
|
private Reference newReference;
|
60
|
|
61
|
private boolean registrationInProgress;
|
62
|
|
63
|
@Autowired
|
64
|
protected CdmFilterablePagingProviderFactory pagingProviderFactory;
|
65
|
|
66
|
private TypifiedEntityFilterablePagingProvider<Reference> referencePagingProvider;
|
67
|
|
68
|
public StartRegistrationPresenter (){
|
69
|
super();
|
70
|
}
|
71
|
|
72
|
|
73
|
/**
|
74
|
* {@inheritDoc}
|
75
|
*/
|
76
|
@Override
|
77
|
public void handleViewEntered() {
|
78
|
|
79
|
super.handleViewEntered();
|
80
|
|
81
|
referencePagingProvider = pagingProviderFactory.referenceEntityReferencePagingProvider(
|
82
|
new ReferenceEllypsisFormatter(ReferenceEllypsisFormatter.LabelType.BIBLIOGRAPHIC),
|
83
|
ReferenceEllypsisFormatter.INIT_STRATEGY
|
84
|
);
|
85
|
TypedEntityCaptionGenerator<Reference> titleCacheGenrator = new TypedEntityCaptionGenerator<Reference>();
|
86
|
referencePagingProvider.addRestriction(new Restriction("type", Operator.AND_NOT, null, ReferenceType.Section, ReferenceType.Journal, ReferenceType.PrintSeries));
|
87
|
getView().getReferenceCombobox().setCaptionGenerator(titleCacheGenrator);
|
88
|
getView().getReferenceCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* @param value
|
93
|
* @return
|
94
|
*/
|
95
|
public void updateReferenceSearchMode(MatchMode value) {
|
96
|
if(referencePagingProvider != null && value != null){
|
97
|
referencePagingProvider.setMatchMode(value);
|
98
|
getView().getReferenceCombobox().refresh();
|
99
|
}
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* {@inheritDoc}
|
104
|
*/
|
105
|
@Override
|
106
|
public void handleViewExit() {
|
107
|
if(!registrationInProgress && newReference != null){
|
108
|
logger.info("Deleting newly created Reference due to canceled registration");
|
109
|
getRepo().getReferenceService().delete(newReference);
|
110
|
}
|
111
|
super.handleViewExit();
|
112
|
}
|
113
|
|
114
|
|
115
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
116
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
117
|
|
118
|
if(getView() == null || getView().getNewPublicationButton() != event.getSource()){
|
119
|
return;
|
120
|
}
|
121
|
|
122
|
newReferencePopup = openPopupEditor(ReferencePopupEditor.class, event);
|
123
|
EnumSet<ReferenceType> refTypes = RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES.clone();
|
124
|
refTypes.remove(ReferenceType.Section);
|
125
|
newReferencePopup.withReferenceTypes(refTypes);
|
126
|
|
127
|
newReferencePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
128
|
newReferencePopup.withDeleteButton(true);
|
129
|
newReferencePopup.loadInEditor(null);
|
130
|
newReferencePopup.getTypeSelect().setValue(ReferenceType.Article);
|
131
|
}
|
132
|
|
133
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Remove.class)
|
134
|
public void onReferenceEditorActionRemove(ReferenceEditorAction event) {
|
135
|
|
136
|
if(getView().getRemoveNewPublicationButton() != event.getSource()){
|
137
|
return;
|
138
|
}
|
139
|
DeleteResult result = getRepo().getReferenceService().delete(newReference);
|
140
|
if(!result.isOk()){
|
141
|
String message = "";
|
142
|
for(Exception e : result.getExceptions()){
|
143
|
message += e.getMessage() + "\n" + e.getStackTrace().toString() + "\n";
|
144
|
}
|
145
|
getView().getRemoveNewPublicationButton().setComponentError(new SystemError(message));
|
146
|
}
|
147
|
|
148
|
getView().getReferenceCombobox().setEnabled(false);
|
149
|
|
150
|
getView().getRemoveNewPublicationButton().setVisible(false);
|
151
|
|
152
|
getView().getNewPublicationButton().setVisible(true);
|
153
|
getView().getNewPublicationLabel().setCaption(null);
|
154
|
getView().getNewPublicationLabel().setVisible(false);
|
155
|
}
|
156
|
|
157
|
@EventBusListenerMethod
|
158
|
public void onDoneWithPopupEvent(DoneWithPopupEvent event){
|
159
|
|
160
|
if(event.getPopup() == newReferencePopup){
|
161
|
if(event.getReason() == Reason.SAVE){
|
162
|
|
163
|
newReference = newReferencePopup.getBean();
|
164
|
|
165
|
// TODO the bean contained in the popup editor is not yet updated at this point.
|
166
|
// so re reload it using the uuid since new beans will not have an Id at this point.
|
167
|
newReference = getRepo().getReferenceService().find(newReference.getUuid());
|
168
|
|
169
|
getView().getReferenceCombobox().setValue(null); // deselect
|
170
|
getView().getReferenceCombobox().setEnabled(false);
|
171
|
|
172
|
getView().getContinueButton().setEnabled(true);
|
173
|
|
174
|
getView().getNewPublicationButton().setVisible(false);
|
175
|
|
176
|
getView().getRemoveNewPublicationButton().setVisible(true);
|
177
|
getView().getNewPublicationLabel().setCaption(newReference.getTitleCache());
|
178
|
getView().getNewPublicationLabel().setVisible(true);
|
179
|
}
|
180
|
|
181
|
newReferencePopup = null;
|
182
|
}
|
183
|
}
|
184
|
|
185
|
@SuppressWarnings("null")
|
186
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
187
|
public void onRegistrationEditorActionAdd(RegistrationEditorAction event) {
|
188
|
|
189
|
if(getView().getContinueButton() != event.getSource()){
|
190
|
return;
|
191
|
}
|
192
|
|
193
|
UUID referenceUuid = null;
|
194
|
LazyComboBox<TypedEntityReference<Reference>> referenceCombobox = getView().getReferenceCombobox();
|
195
|
referenceCombobox.commit();
|
196
|
if(newReference != null){
|
197
|
referenceUuid = newReference.getUuid();
|
198
|
// } else if(referenceCombobox.getValue() != null) {
|
199
|
} else if ( event.getEntityUuid() != null) { // HACKED, see view implementation
|
200
|
referenceUuid = event.getEntityUuid();
|
201
|
}
|
202
|
if(referenceUuid == null){
|
203
|
getView().getContinueButton().setComponentError(new UserError("Can't continue. No Reference is chosen."));
|
204
|
getView().getContinueButton().setEnabled(false);
|
205
|
}
|
206
|
registrationInProgress = true;
|
207
|
viewEventBus.publish(EventScope.UI, this, new NavigationEvent(RegistrationWorksetViewBean.NAME, referenceUuid.toString()));
|
208
|
|
209
|
}
|
210
|
|
211
|
/**
|
212
|
* {@inheritDoc}
|
213
|
*/
|
214
|
@Override
|
215
|
protected RegistrationDTO loadBeanById(Object identifier) {
|
216
|
// not needed //
|
217
|
return null;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* {@inheritDoc}
|
222
|
*/
|
223
|
@Override
|
224
|
protected void saveBean(RegistrationDTO bean) {
|
225
|
// not needed //
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* {@inheritDoc}
|
230
|
*/
|
231
|
@Override
|
232
|
protected void deleteBean(RegistrationDTO bean) {
|
233
|
// not needed //
|
234
|
}
|
235
|
|
236
|
}
|