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.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.springframework.context.annotation.Scope;
|
16
|
|
17
|
import com.vaadin.spring.annotation.SpringComponent;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
20
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
21
|
import eu.etaxonomy.cdm.model.common.User;
|
22
|
import eu.etaxonomy.cdm.model.name.Registration;
|
23
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
24
|
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
|
25
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
|
26
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
27
|
|
28
|
/**
|
29
|
* @author a.kohlbecker
|
30
|
* @since May 15, 2017
|
31
|
*
|
32
|
*/
|
33
|
@SpringComponent
|
34
|
@Scope("prototype")
|
35
|
public class RegistrationEditorPresenter extends AbstractCdmEditorPresenter<Registration, RegistrationPopEditorView> {
|
36
|
|
37
|
private static final long serialVersionUID = 6930557602995331944L;
|
38
|
|
39
|
/**
|
40
|
* {@inheritDoc}
|
41
|
*/
|
42
|
@Override
|
43
|
protected IRegistrationService getService() {
|
44
|
return getRepo().getRegistrationService();
|
45
|
}
|
46
|
|
47
|
|
48
|
protected static BeanInstantiator<Registration> defaultBeanInstantiator = new BeanInstantiator<Registration>() {
|
49
|
|
50
|
@Override
|
51
|
public Registration createNewBean() {
|
52
|
return Registration.NewInstance();
|
53
|
}
|
54
|
};
|
55
|
|
56
|
|
57
|
@Override
|
58
|
protected BeanInstantiator<Registration> defaultBeanInstantiator(){
|
59
|
return defaultBeanInstantiator;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* {@inheritDoc}
|
64
|
*/
|
65
|
@Override
|
66
|
protected Registration loadCdmEntity(UUID identifier) {
|
67
|
|
68
|
Registration reg;
|
69
|
if(identifier != null){
|
70
|
List<String> initStrategy = Arrays.asList(new String[] {"$", "typeDesignations"});
|
71
|
reg = getRepo().getRegistrationService().load(identifier, initStrategy );
|
72
|
} else {
|
73
|
reg = createNewBean();
|
74
|
}
|
75
|
return reg;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* {@inheritDoc}
|
80
|
*/
|
81
|
@Override
|
82
|
protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
|
83
|
if(crud != null){
|
84
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(Registration.class, identifier, crud, null);
|
85
|
}
|
86
|
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* {@inheritDoc}
|
91
|
*/
|
92
|
@Override
|
93
|
protected void guaranteePerEntityCRUDPermissions(Registration bean) {
|
94
|
if(crud != null){
|
95
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
|
96
|
}
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* {@inheritDoc}
|
101
|
*/
|
102
|
@Override
|
103
|
public void handleViewEntered() {
|
104
|
super.handleViewEntered();
|
105
|
|
106
|
CdmBeanItemContainerFactory selectFieldFactory = new CdmBeanItemContainerFactory(getRepo());
|
107
|
|
108
|
getView().getInstitutionField().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(Institution.class));
|
109
|
getView().getInstitutionField().setItemCaptionPropertyId("titleCache");
|
110
|
|
111
|
getView().getSubmitterField().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(User.class));
|
112
|
getView().getSubmitterField().setItemCaptionPropertyId("username");
|
113
|
}
|
114
|
|
115
|
|
116
|
|
117
|
}
|