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.Arrays;
|
12
|
import java.util.Date;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.springframework.context.annotation.Scope;
|
17
|
|
18
|
import com.vaadin.spring.annotation.SpringComponent;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
21
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
22
|
import eu.etaxonomy.cdm.model.name.Registration;
|
23
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
24
|
import eu.etaxonomy.cdm.model.permission.User;
|
25
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
26
|
import eu.etaxonomy.cdm.vaadin.util.converter.JodaDateTimeConverter;
|
27
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
|
28
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
29
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
30
|
|
31
|
/**
|
32
|
* @author a.kohlbecker
|
33
|
* @since May 15, 2017
|
34
|
*
|
35
|
*/
|
36
|
@SpringComponent
|
37
|
@Scope("prototype")
|
38
|
public class RegistrationEditorPresenter extends AbstractCdmEditorPresenter<Registration, RegistrationPopEditorView> {
|
39
|
|
40
|
private static final long serialVersionUID = 6930557602995331944L;
|
41
|
private RegistrationStatus lastStatus;
|
42
|
|
43
|
/**
|
44
|
* {@inheritDoc}
|
45
|
*/
|
46
|
@Override
|
47
|
protected IRegistrationService getService() {
|
48
|
return getRepo().getRegistrationService();
|
49
|
}
|
50
|
|
51
|
|
52
|
protected static BeanInstantiator<Registration> defaultBeanInstantiator = new BeanInstantiator<Registration>() {
|
53
|
|
54
|
@Override
|
55
|
public Registration createNewBean() {
|
56
|
return Registration.NewInstance();
|
57
|
}
|
58
|
};
|
59
|
|
60
|
|
61
|
@Override
|
62
|
protected BeanInstantiator<Registration> defaultBeanInstantiator(){
|
63
|
return defaultBeanInstantiator;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* {@inheritDoc}
|
68
|
*/
|
69
|
@Override
|
70
|
protected Registration loadCdmEntity(UUID identifier) {
|
71
|
|
72
|
Registration reg;
|
73
|
if(identifier != null){
|
74
|
List<String> initStrategy = Arrays.asList(new String[] {"$", "typeDesignations"});
|
75
|
reg = getRepo().getRegistrationService().load(identifier, initStrategy );
|
76
|
} else {
|
77
|
reg = createNewBean();
|
78
|
}
|
79
|
return reg;
|
80
|
}
|
81
|
|
82
|
|
83
|
|
84
|
/**
|
85
|
* {@inheritDoc}
|
86
|
*/
|
87
|
@Override
|
88
|
protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
|
89
|
if(crud != null){
|
90
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(Registration.class, identifier, crud, null);
|
91
|
}
|
92
|
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* {@inheritDoc}
|
97
|
*/
|
98
|
@Override
|
99
|
protected void guaranteePerEntityCRUDPermissions(Registration bean) {
|
100
|
if(crud != null){
|
101
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
|
102
|
}
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* {@inheritDoc}
|
107
|
*/
|
108
|
@Override
|
109
|
public void handleViewEntered() {
|
110
|
super.handleViewEntered();
|
111
|
|
112
|
getView().getInstitutionField().setContainerDataSource(cdmBeanItemContainerFactory.buildBeanItemContainer(Institution.class));
|
113
|
getView().getInstitutionField().setItemCaptionPropertyId("titleCache");
|
114
|
|
115
|
getView().getSubmitterField().setContainerDataSource(cdmBeanItemContainerFactory.buildBeanItemContainer(User.class));
|
116
|
getView().getSubmitterField().setItemCaptionPropertyId("username");
|
117
|
|
118
|
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
protected void adaptDataProviders() {
|
123
|
getView().getStatusSelect().addValueChangeListener( e -> updateRegStatus((RegistrationStatus) e.getProperty().getValue()) );
|
124
|
}
|
125
|
|
126
|
private void updateRegStatus(RegistrationStatus status){
|
127
|
Registration reg = ((AbstractPopupEditor<Registration, RegistrationEditorPresenter>)getView()).getBean();
|
128
|
if(lastStatus != null){
|
129
|
// set last status again to allow updateStatusAndDate() to the job
|
130
|
reg.setStatus(lastStatus);
|
131
|
}
|
132
|
reg.updateStatusAndDate(status);
|
133
|
lastStatus = status;
|
134
|
JodaDateTimeConverter converter = new JodaDateTimeConverter();
|
135
|
getView().getRegistrationDateField().setValue(converter.convertToPresentation(reg.getRegistrationDate(), Date.class, null));
|
136
|
}
|
137
|
|
138
|
|
139
|
|
140
|
}
|