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.name;
|
10
|
|
11
|
import java.util.EnumSet;
|
12
|
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.vaadin.viritin.fields.AbstractElementCollection;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
17
|
import eu.etaxonomy.cdm.cache.CdmEntityCache;
|
18
|
import eu.etaxonomy.cdm.cache.EntityCache;
|
19
|
import eu.etaxonomy.cdm.model.location.Country;
|
20
|
import eu.etaxonomy.cdm.model.name.Registration;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
22
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
23
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
24
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
25
|
import eu.etaxonomy.cdm.service.CdmStore;
|
26
|
import eu.etaxonomy.cdm.service.ISpecimenTypeDesignationWorkingSetService;
|
27
|
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
|
28
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
|
29
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
30
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationTermLists;
|
31
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
32
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
33
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
34
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
35
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
36
|
/**
|
37
|
* SpecimenTypeDesignationWorkingsetPopupEditorView implementation must override the showInEditor() method,
|
38
|
* see {@link #prepareAsFieldGroupDataSource()} for details.
|
39
|
*
|
40
|
* @author a.kohlbecker
|
41
|
* @since Jun 13, 2017
|
42
|
*
|
43
|
*/
|
44
|
public class SpecimenTypeDesignationWorkingsetEditorPresenter
|
45
|
extends AbstractEditorPresenter<SpecimenTypeDesignationWorkingSetDTO , SpecimenTypeDesignationWorkingsetPopupEditorView>
|
46
|
implements CachingPresenter {
|
47
|
|
48
|
private static final long serialVersionUID = 4255636253714476918L;
|
49
|
|
50
|
CdmStore<Registration, IRegistrationService> store;
|
51
|
|
52
|
|
53
|
/**
|
54
|
* This object for this field will either be injected by the {@link PopupEditorFactory} or by a Spring
|
55
|
* {@link BeanFactory}
|
56
|
*/
|
57
|
@Autowired
|
58
|
private ISpecimenTypeDesignationWorkingSetService specimenTypeDesignationWorkingSetService;
|
59
|
|
60
|
/**
|
61
|
* if not null, this CRUD set is to be used to create a CdmAuthoritiy for the base entitiy which will be
|
62
|
* granted to the current use as long this grant is not assigned yet.
|
63
|
*/
|
64
|
private EnumSet<CRUD> crud = null;
|
65
|
|
66
|
private CdmEntityCache cache = null;
|
67
|
|
68
|
protected CdmStore<Registration, IRegistrationService> getStore() {
|
69
|
if(store == null){
|
70
|
store = new CdmStore<>(getRepo(), getRepo().getRegistrationService());
|
71
|
}
|
72
|
return store;
|
73
|
}
|
74
|
|
75
|
|
76
|
/**
|
77
|
* Loads an existing working set from the database. This process actually involves
|
78
|
* loading the Registration specified by the <code>RegistrationAndWorkingsetId.registrationId</code> and in
|
79
|
* a second step to find the workingset by the <code>registrationAndWorkingsetId.workingsetId</code>.
|
80
|
* <p>
|
81
|
* The <code>identifier</code> must be of the type {@link TypeDesignationWorkingsetEditorIdSet} whereas the field <code>egistrationId</code>
|
82
|
* must be present, the field <code>workingsetId</code>, however can be null. I this case a new workingset with a new {@link FieldUnit} as
|
83
|
* base entity is being created.
|
84
|
*
|
85
|
* @param identifier a {@link TypeDesignationWorkingsetEditorIdSet}
|
86
|
*/
|
87
|
@Override
|
88
|
protected SpecimenTypeDesignationWorkingSetDTO<Registration> loadBeanById(Object identifier) {
|
89
|
|
90
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingSetDto;
|
91
|
if(identifier != null){
|
92
|
|
93
|
TypeDesignationWorkingsetEditorIdSet idset = (TypeDesignationWorkingsetEditorIdSet)identifier;
|
94
|
|
95
|
if(idset.workingsetId != null){
|
96
|
workingSetDto = specimenTypeDesignationWorkingSetService.loadDtoByIds(idset.registrationId, idset.workingsetId);
|
97
|
if(workingSetDto.getFieldUnit() == null){
|
98
|
workingSetDto = specimenTypeDesignationWorkingSetService.fixMissingFieldUnit(workingSetDto);
|
99
|
// FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
|
100
|
// This method must go again into the presenter !!!!
|
101
|
logger.info("Basing all typeDesignations on a new fieldUnit");
|
102
|
}
|
103
|
cache = new CdmEntityCache(workingSetDto.getOwner());
|
104
|
} else {
|
105
|
// create a new workingset, for a new fieldunit which is the base for the workingset
|
106
|
workingSetDto = specimenTypeDesignationWorkingSetService.create(idset.registrationId, idset.publicationId, idset.typifiedNameId);
|
107
|
cache = new CdmEntityCache(workingSetDto.getOwner());
|
108
|
}
|
109
|
|
110
|
} else {
|
111
|
workingSetDto = null;
|
112
|
}
|
113
|
|
114
|
return workingSetDto;
|
115
|
}
|
116
|
|
117
|
|
118
|
/**
|
119
|
* {@inheritDoc}
|
120
|
*/
|
121
|
@SuppressWarnings("serial")
|
122
|
@Override
|
123
|
public void handleViewEntered() {
|
124
|
|
125
|
CdmBeanItemContainerFactory selectFactory = new CdmBeanItemContainerFactory(getRepo());
|
126
|
getView().getCountrySelectField().setContainerDataSource(selectFactory.buildBeanItemContainer(Country.uuidCountryVocabulary));
|
127
|
|
128
|
getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
|
129
|
|
130
|
CdmFilterablePagingProvider<Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection>(getRepo().getCollectionService());
|
131
|
|
132
|
CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService());
|
133
|
|
134
|
@Override
|
135
|
public SpecimenTypeDesignationDTORow create() {
|
136
|
|
137
|
SpecimenTypeDesignationDTORow row = new SpecimenTypeDesignationDTORow();
|
138
|
|
139
|
row.kindOfUnit.setContainerDataSource(selectFactory.buildTermItemContainer(
|
140
|
RegistrationTermLists.KIND_OF_UNIT_TERM_UUIDS())
|
141
|
);
|
142
|
row.kindOfUnit.setNullSelectionAllowed(false);
|
143
|
|
144
|
row.typeStatus.setContainerDataSource(selectFactory.buildTermItemContainer(
|
145
|
RegistrationTermLists.SPECIMEN_TYPE_DESIGNATION_STATUS_UUIDS())
|
146
|
);
|
147
|
row.typeStatus.setNullSelectionAllowed(false);
|
148
|
|
149
|
|
150
|
row.collection.loadFrom(
|
151
|
collectionPagingProvider,
|
152
|
collectionPagingProvider,
|
153
|
collectionPagingProvider.getPageSize()
|
154
|
);
|
155
|
row.collection.getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Collection>());
|
156
|
row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Collection>(row.collection));
|
157
|
row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(row.collection.getSelect(), SpecimenTypeDesignationWorkingsetEditorPresenter.this));
|
158
|
|
159
|
row.mediaSpecimenReference.loadFrom(
|
160
|
referencePagingProvider,
|
161
|
referencePagingProvider,
|
162
|
collectionPagingProvider.getPageSize()
|
163
|
);
|
164
|
|
165
|
row.mediaSpecimenReference.getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
|
166
|
row.mediaSpecimenReference.getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(row.mediaSpecimenReference));
|
167
|
|
168
|
getView().applyDefaultComponentStyle(row.components());
|
169
|
|
170
|
return row;
|
171
|
}
|
172
|
|
173
|
});
|
174
|
|
175
|
}
|
176
|
|
177
|
|
178
|
/**
|
179
|
* {@inheritDoc}
|
180
|
*/
|
181
|
@Override
|
182
|
protected void saveBean(SpecimenTypeDesignationWorkingSetDTO dto) {
|
183
|
if(crud != null){
|
184
|
UserHelper.fromSession().createAuthorityForCurrentUser(dto.getFieldUnit(), crud, null);
|
185
|
}
|
186
|
|
187
|
specimenTypeDesignationWorkingSetService.save(dto);
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* {@inheritDoc}
|
192
|
*/
|
193
|
@Override
|
194
|
protected void deleteBean(SpecimenTypeDesignationWorkingSetDTO bean) {
|
195
|
// TODO Auto-generated method stub
|
196
|
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* @param crud
|
201
|
*/
|
202
|
public void setGrantsForCurrentUser(EnumSet<CRUD> crud) {
|
203
|
this.crud = crud;
|
204
|
|
205
|
}
|
206
|
|
207
|
/**
|
208
|
* {@inheritDoc}
|
209
|
*/
|
210
|
@Override
|
211
|
public EntityCache getCache() {
|
212
|
if(((AbstractPopupEditor)getView()).isBeanLoaded()){
|
213
|
return cache;
|
214
|
} else {
|
215
|
return null;
|
216
|
}
|
217
|
}
|
218
|
|
219
|
}
|