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.Arrays;
|
12
|
import java.util.EnumSet;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Optional;
|
18
|
import java.util.Set;
|
19
|
import java.util.Stack;
|
20
|
import java.util.stream.Collectors;
|
21
|
|
22
|
import org.apache.logging.log4j.LogManager;
|
23
|
import org.apache.logging.log4j.Logger;
|
24
|
import org.hibernate.criterion.Restrictions;
|
25
|
import org.springframework.beans.factory.annotation.Autowired;
|
26
|
import org.springframework.context.annotation.Scope;
|
27
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
28
|
import org.vaadin.viritin.fields.AbstractElementCollection;
|
29
|
import org.vaadin.viritin.fields.ElementCollectionField;
|
30
|
|
31
|
import com.vaadin.data.util.BeanItemContainer;
|
32
|
import com.vaadin.spring.annotation.SpringComponent;
|
33
|
|
34
|
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
|
35
|
import eu.etaxonomy.cdm.cache.CdmTransientEntityAndUuidCacher;
|
36
|
import eu.etaxonomy.cdm.format.reference.ReferenceEllypsisFormatter.LabelType;
|
37
|
import eu.etaxonomy.cdm.model.ICdmEntityUuidCacher;
|
38
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
39
|
import eu.etaxonomy.cdm.model.agent.Person;
|
40
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
41
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
42
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
43
|
import eu.etaxonomy.cdm.model.location.Country;
|
44
|
import eu.etaxonomy.cdm.model.name.Registration;
|
45
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
46
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
47
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
48
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
49
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
50
|
import eu.etaxonomy.cdm.model.permission.CRUD;
|
51
|
import eu.etaxonomy.cdm.model.reference.NamedSource;
|
52
|
import eu.etaxonomy.cdm.model.reference.NamedSourceBase;
|
53
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
54
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
55
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
56
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
57
|
import eu.etaxonomy.cdm.model.term.TermType;
|
58
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
|
59
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction.Operator;
|
60
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
61
|
import eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory;
|
62
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
63
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProviderFactory;
|
64
|
import eu.etaxonomy.cdm.service.ISpecimenTypeDesignationSetService;
|
65
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
66
|
import eu.etaxonomy.cdm.service.initstrategies.AgentBaseInit;
|
67
|
import eu.etaxonomy.cdm.vaadin.component.CollectionRowItemCollection;
|
68
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionContext;
|
69
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
70
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEventFilter;
|
71
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
72
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationTermLists;
|
73
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
|
74
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationSetDTO;
|
75
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
76
|
import eu.etaxonomy.cdm.vaadin.util.CollectionCaptionGenerator;
|
77
|
import eu.etaxonomy.cdm.vaadin.util.ReferenceEllypsisCaptionGenerator;
|
78
|
import eu.etaxonomy.cdm.vaadin.util.fields.ElementCollectionHelper;
|
79
|
import eu.etaxonomy.cdm.vaadin.view.occurrence.CollectionPopupEditor;
|
80
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
81
|
import eu.etaxonomy.cdm.vaadin.view.reference.RegistrationUiReferenceEditorFormConfigurator;
|
82
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
83
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
84
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
85
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
86
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
87
|
/**
|
88
|
* SpecimenTypeDesignationSetPopupEditorView implementation must override the showInEditor() method,
|
89
|
* see {@link #prepareAsFieldGroupDataSource()} for details.
|
90
|
*
|
91
|
* @author a.kohlbecker
|
92
|
* @since Jun 13, 2017
|
93
|
*/
|
94
|
@SpringComponent
|
95
|
@Scope("prototype")
|
96
|
public class SpecimenTypeDesignationSetEditorPresenter
|
97
|
extends AbstractEditorPresenter<SpecimenTypeDesignationSetDTO,SpecimenTypeDesignationSetPopupEditorView>
|
98
|
implements CachingPresenter, NomenclaturalActContext {
|
99
|
|
100
|
private static final long serialVersionUID = 4255636253714476918L;
|
101
|
|
102
|
private final static Logger logger = LogManager.getLogger();
|
103
|
|
104
|
private static final EnumSet<CRUD> COLLECTION_EDITOR_CRUD = EnumSet.of(CRUD.UPDATE, CRUD.DELETE);
|
105
|
|
106
|
/**
|
107
|
* This object for this field will either be injected by the {@link PopupEditorFactory} or by a Spring
|
108
|
* {@link BeanFactory}
|
109
|
*/
|
110
|
@Autowired
|
111
|
private ISpecimenTypeDesignationSetService specimenTypeDesignationSetService;
|
112
|
|
113
|
@Autowired
|
114
|
private CdmFilterablePagingProviderFactory pagingProviderFactory;
|
115
|
|
116
|
@Autowired
|
117
|
private CdmBeanItemContainerFactory cdmBeanItemContainerFactory;
|
118
|
|
119
|
/**
|
120
|
* if not null, this CRUD set is to be used to create a CdmAuthoritiy for the base entitiy which will be
|
121
|
* granted to the current use as long this grant is not assigned yet.
|
122
|
*/
|
123
|
private EnumSet<CRUD> crud = null;
|
124
|
|
125
|
private ICdmEntityUuidCacher cache;
|
126
|
|
127
|
private SpecimenTypeDesignationSetDTO<Registration> workingSetDto;
|
128
|
|
129
|
private CdmFilterablePagingProvider<Reference, Reference> designationReferencePagingProvider;
|
130
|
|
131
|
private CdmFilterablePagingProvider<Reference, Reference> mediaReferencePagingProvider;
|
132
|
|
133
|
/**
|
134
|
* The unit of publication in which the type designation has been published.
|
135
|
* This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
|
136
|
* but never a {@link ReferenceType#Section}
|
137
|
*/
|
138
|
private NamedSourceBase publishedUnit;
|
139
|
|
140
|
private Map<CollectionPopupEditor, SpecimenTypeDesignationDTORow> collectionPopupEditorsRowMap = new HashMap<>();
|
141
|
|
142
|
private Map<ReferencePopupEditor, ToOneRelatedEntityCombobox<Reference>> referencePopupEditorsCombobox = new HashMap<>();
|
143
|
|
144
|
private ElementCollectionHelper<ElementCollectionField<?>> typeDesignationsCollectionFieldHelper;
|
145
|
|
146
|
private Set<CollectionRowItemCollection> typeDesignationEditorRows = new HashSet<>();
|
147
|
|
148
|
private java.util.Collection<CdmBase> rootEntities = new HashSet<>();
|
149
|
|
150
|
private BeanInstantiator<Reference> newReferenceInstantiator;
|
151
|
|
152
|
private Optional<Boolean> isInTypedesignationOnlyAct = Optional.empty();
|
153
|
|
154
|
/**
|
155
|
* Loads an existing working set from the database. This process actually involves
|
156
|
* loading the Registration specified by the <code>RegistrationAndWorkingsetId.registrationId</code> and in
|
157
|
* a second step to find the workingset by the <code>registrationAndWorkingsetId.workingsetId</code>.
|
158
|
* <p>
|
159
|
* The <code>identifier</code> must be of the type {@link TypeDesignationSetIds} whereas the
|
160
|
* field <code>registrationId</code> must be present.
|
161
|
* The field <code>workingsetId</code> however can be null.
|
162
|
* I this case a new workingset with a new {@link FieldUnit} as
|
163
|
* base entity is being created.
|
164
|
*
|
165
|
* @param identifier a {@link TypeDesignationSetIds}
|
166
|
*/
|
167
|
@Override
|
168
|
protected SpecimenTypeDesignationSetDTO<Registration> loadBeanById(Object identifier) {
|
169
|
|
170
|
cache = new CdmTransientEntityAndUuidCacher(this);
|
171
|
if(identifier != null){
|
172
|
|
173
|
SpecimenTypeDesignationSetIds idset = (SpecimenTypeDesignationSetIds)identifier;
|
174
|
|
175
|
if(idset.baseEntity != null){
|
176
|
// load existing workingset
|
177
|
workingSetDto = specimenTypeDesignationSetService.load(idset.registrationUuid, idset.baseEntity);
|
178
|
if(workingSetDto.getFieldUnit() == null){
|
179
|
workingSetDto = specimenTypeDesignationSetService.fixMissingFieldUnit(workingSetDto);
|
180
|
// FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
|
181
|
// This method must go again into the presenter !!!!
|
182
|
logger.info("Basing all typeDesignations on a new fieldUnit");
|
183
|
}
|
184
|
} else {
|
185
|
// create a new workingset, for a new fieldunit which is the base for the workingset
|
186
|
workingSetDto = specimenTypeDesignationSetService.create(idset.getRegistrationUUID(), idset.getTypifiedNameUuid());
|
187
|
cache.load(workingSetDto.getTypifiedName());
|
188
|
rootEntities.add(workingSetDto.getTypifiedName());
|
189
|
}
|
190
|
Registration registration = workingSetDto.getOwner();
|
191
|
// need to use load() but put() see #7214
|
192
|
cache.load(registration);
|
193
|
rootEntities.add(registration);
|
194
|
setInTypedesignationOnlyAct(Optional.of(Boolean.valueOf(registration.getName() == null)));
|
195
|
try {
|
196
|
NamedSourceBase pubUnitSource = RegistrationDTO.findPublishedUnit(registration);
|
197
|
if(pubUnitSource == null) {
|
198
|
Reference reference = getRepo().getReferenceService().load(idset.getPublishedUnitUuid());
|
199
|
pubUnitSource = NamedSource.NewPrimarySourceInstance(reference, null);
|
200
|
}
|
201
|
setPublishedUnit(pubUnitSource);
|
202
|
} catch (Exception e) {
|
203
|
// FIXME report error state instead
|
204
|
logger.error("Error on finding published unit in " + registration.toString(), e);
|
205
|
}
|
206
|
} else {
|
207
|
workingSetDto = null;
|
208
|
}
|
209
|
|
210
|
if (getPublishedUnit() != null) {
|
211
|
// reduce available references to those which are sections of
|
212
|
// the publicationUnit and the publishedUnit itself
|
213
|
designationReferencePagingProvider.getCriteria()
|
214
|
.add(Restrictions.or(
|
215
|
Restrictions.and(
|
216
|
Restrictions.eq("inReference", publishedUnit.getCitation()),
|
217
|
Restrictions.eq("type", ReferenceType.Section)),
|
218
|
Restrictions.idEq(publishedUnit.getCitation().getId()))
|
219
|
);
|
220
|
// new Reference only a sub sections of the publishedUnit
|
221
|
newReferenceInstantiator = new BeanInstantiator<Reference>() {
|
222
|
@Override
|
223
|
public Reference createNewBean() {
|
224
|
Reference newRef = ReferenceFactory.newSection();
|
225
|
newRef.setInReference(publishedUnit.getCitation());
|
226
|
return newRef;
|
227
|
}
|
228
|
};
|
229
|
}
|
230
|
|
231
|
// new Reference only a sub sections of the publishedUnit
|
232
|
newReferenceInstantiator = new BeanInstantiator<Reference>() {
|
233
|
@Override
|
234
|
public Reference createNewBean() {
|
235
|
Reference newRef = ReferenceFactory.newSection();
|
236
|
newRef.setInReference(publishedUnit.getCitation());
|
237
|
return newRef;
|
238
|
}
|
239
|
};
|
240
|
|
241
|
return workingSetDto;
|
242
|
}
|
243
|
|
244
|
|
245
|
/**
|
246
|
* {@inheritDoc}
|
247
|
*/
|
248
|
@SuppressWarnings("serial")
|
249
|
@Override
|
250
|
public void handleViewEntered() {
|
251
|
|
252
|
getView().getCountrySelectField().setContainerDataSource(cdmBeanItemContainerFactory.buildVocabularyTermsItemContainer(Country.uuidCountryVocabulary));
|
253
|
|
254
|
CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> termOrPersonPagingProvider = pagingProviderFactory.teamOrPersonPagingProvider();
|
255
|
CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider = pagingProviderFactory.personPagingProvider();
|
256
|
termOrPersonPagingProvider.setInitStrategy(AgentBaseInit.TEAM_OR_PERSON_INIT_STRATEGY);
|
257
|
// the ToOneRelatedEntityReloader is added internally in the TeamOrPersonField:
|
258
|
getView().getCollectorField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
259
|
getView().getCollectorField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
260
|
|
261
|
getView().getExactLocationField().getReferenceSystemSelect().setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(TermType.ReferenceSystem));
|
262
|
getView().getExactLocationField().getReferenceSystemSelect().setItemCaptionPropertyId("label");
|
263
|
|
264
|
getView().getTypeDesignationsCollectionField().addElementRemovedListener(e -> deleteTypeDesignation(e.getElement()));
|
265
|
getView().getTypeDesignationsCollectionField().addElementAddedListener(e -> addTypeDesignation(e.getElement()));
|
266
|
|
267
|
getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildVocabularyTermsItemContainer(
|
268
|
AnnotationType.EDITORIAL().getVocabulary().getUuid()));
|
269
|
|
270
|
typeDesignationEditorRows.clear();
|
271
|
CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
|
272
|
collectionPagingProvider.getRestrictions().add(new Restriction<>("institute.titleCache", Operator.OR, MatchMode.ANYWHERE, CdmFilterablePagingProvider.QUERY_STRING_PLACEHOLDER));
|
273
|
|
274
|
designationReferencePagingProvider = pagingProviderFactory.referencePagingProvider();
|
275
|
mediaReferencePagingProvider = pagingProviderFactory.referencePagingProvider();
|
276
|
|
277
|
typeDesignationsCollectionFieldHelper = new ElementCollectionHelper(getView().getTypeDesignationsCollectionField());
|
278
|
getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
|
279
|
|
280
|
@Override
|
281
|
public SpecimenTypeDesignationDTORow create() {
|
282
|
|
283
|
SpecimenTypeDesignationDTORow row = new SpecimenTypeDesignationDTORow();
|
284
|
|
285
|
row.kindOfUnit.setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(
|
286
|
RegistrationTermLists.KIND_OF_UNIT_TERM_UUIDS())
|
287
|
);
|
288
|
row.kindOfUnit.setNullSelectionAllowed(false);
|
289
|
|
290
|
row.typeStatus.setContainerDataSource(provideTypeStatusTermItemContainer());
|
291
|
row.typeStatus.setNullSelectionAllowed(false);
|
292
|
|
293
|
|
294
|
row.collection.loadFrom(
|
295
|
collectionPagingProvider,
|
296
|
collectionPagingProvider,
|
297
|
collectionPagingProvider.getPageSize()
|
298
|
);
|
299
|
row.collection.getSelect().setCaptionGenerator(new CollectionCaptionGenerator());
|
300
|
row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(row.collection.getSelect(),
|
301
|
SpecimenTypeDesignationSetEditorPresenter.this));
|
302
|
row.collection.addClickListenerAddEntity(e -> doCollectionEditorAdd(row));
|
303
|
row.collection.addClickListenerEditEntity(e -> {
|
304
|
if(row.collection.getValue() != null){
|
305
|
doCollectionEditorEdit(row);
|
306
|
}
|
307
|
});
|
308
|
|
309
|
row.designationReference.loadFrom(
|
310
|
designationReferencePagingProvider,
|
311
|
designationReferencePagingProvider,
|
312
|
designationReferencePagingProvider.getPageSize()
|
313
|
);
|
314
|
row.designationReference.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC, row.designationReference.getSelect()));
|
315
|
row.designationReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.designationReference.getSelect(),
|
316
|
SpecimenTypeDesignationSetEditorPresenter.this));
|
317
|
row.designationReference.addClickListenerAddEntity(e -> doReferenceEditorAdd(row.designationReference));
|
318
|
row.designationReference.addClickListenerEditEntity(e -> {
|
319
|
if(row.designationReference.getValue() != null){
|
320
|
doReferenceEditorEdit(row.designationReference);
|
321
|
}
|
322
|
});
|
323
|
row.designationReference.setRequired(checkInTypeDesignationOnlyAct());
|
324
|
row.designationReference.getSelect().setNullSelectionAllowed(!checkInTypeDesignationOnlyAct());
|
325
|
|
326
|
row.mediaSpecimenReference.loadFrom(
|
327
|
mediaReferencePagingProvider,
|
328
|
mediaReferencePagingProvider,
|
329
|
mediaReferencePagingProvider.getPageSize()
|
330
|
);
|
331
|
row.mediaSpecimenReference.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC, row.mediaSpecimenReference.getSelect()));
|
332
|
row.mediaSpecimenReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.mediaSpecimenReference.getSelect(),
|
333
|
SpecimenTypeDesignationSetEditorPresenter.this));
|
334
|
row.mediaSpecimenReference.addClickListenerAddEntity(e -> doReferenceEditorAdd(row.mediaSpecimenReference));
|
335
|
row.mediaSpecimenReference.addClickListenerEditEntity(e -> {
|
336
|
if(row.mediaSpecimenReference.getValue() != null){
|
337
|
doReferenceEditorEdit(row.mediaSpecimenReference);
|
338
|
}
|
339
|
});
|
340
|
|
341
|
getView().applyDefaultComponentStyle(row.components());
|
342
|
|
343
|
typeDesignationEditorRows.add(row);
|
344
|
|
345
|
return row;
|
346
|
}
|
347
|
});
|
348
|
}
|
349
|
|
350
|
protected BeanItemContainer<DefinedTermBase> provideTypeStatusTermItemContainer() {
|
351
|
BeanItemContainer<DefinedTermBase> container = cdmBeanItemContainerFactory.buildTermItemContainer(
|
352
|
RegistrationTermLists.SPECIMEN_TYPE_DESIGNATION_STATUS_UUIDS());
|
353
|
List<TypeDesignationStatusBase> filteredItems = container.getItemIds().stream()
|
354
|
.filter(t -> t instanceof SpecimenTypeDesignationStatus)
|
355
|
.map(t -> (SpecimenTypeDesignationStatus)t)
|
356
|
.filter(tsb ->
|
357
|
!checkInTypeDesignationOnlyAct()
|
358
|
|| tsb.hasDesignationSource() == true
|
359
|
)
|
360
|
.collect(Collectors.toList());
|
361
|
container.removeAllItems();
|
362
|
container.addAll(filteredItems);
|
363
|
return container;
|
364
|
}
|
365
|
|
366
|
/**
|
367
|
* {@inheritDoc}
|
368
|
*/
|
369
|
@Override
|
370
|
protected void saveBean(SpecimenTypeDesignationSetDTO dto) {
|
371
|
|
372
|
if(crud != null){
|
373
|
UserHelperAccess.userHelper().createAuthorityForCurrentUser(dto.getFieldUnit(), crud, null);
|
374
|
}
|
375
|
|
376
|
List<SpecimenTypeDesignationDTO> stdDTOs = dto.getSpecimenTypeDesignationDTOs();
|
377
|
for(SpecimenTypeDesignationDTO stddto : stdDTOs) {
|
378
|
// clean up
|
379
|
if(!stddto.getTypeStatus().hasDesignationSource()) {
|
380
|
stddto.setDesignationReference(null);
|
381
|
stddto.setDesignationReferenceDetail(null);
|
382
|
}
|
383
|
}
|
384
|
|
385
|
specimenTypeDesignationSetService.save(dto);
|
386
|
}
|
387
|
|
388
|
/**
|
389
|
* {@inheritDoc}
|
390
|
*/
|
391
|
@Override
|
392
|
protected void deleteBean(SpecimenTypeDesignationSetDTO bean) {
|
393
|
specimenTypeDesignationSetService.delete(bean, true);
|
394
|
}
|
395
|
|
396
|
/**
|
397
|
* @param element
|
398
|
* @return
|
399
|
*/
|
400
|
private void addTypeDesignation(SpecimenTypeDesignationDTO element) {
|
401
|
getView().updateAllowDeleteTypeDesignation();
|
402
|
}
|
403
|
|
404
|
|
405
|
/**
|
406
|
* In this method the SpecimenTypeDesignation is dissociated from the Registration.
|
407
|
* The actual deletion of the SpecimenTypeDesignation and DerivedUnit will take place in {@link #saveBean(SpecimenTypeDesignationSetDTO)}
|
408
|
*
|
409
|
* TODO once https://dev.e-taxonomy.eu/redmine/issues/7077 is fixed dissociating from the Registration could be removed here
|
410
|
*
|
411
|
* @param e
|
412
|
* @return
|
413
|
*/
|
414
|
private void deleteTypeDesignation(SpecimenTypeDesignationDTO element) {
|
415
|
|
416
|
Registration reg = workingSetDto.getOwner();
|
417
|
SpecimenTypeDesignation std = element.asSpecimenTypeDesignation();
|
418
|
|
419
|
reg.getTypeDesignations().remove(std);
|
420
|
|
421
|
getView().updateAllowDeleteTypeDesignation();
|
422
|
}
|
423
|
|
424
|
/**
|
425
|
* @param crud
|
426
|
*/
|
427
|
public void setGrantsForCurrentUser(EnumSet<CRUD> crud) {
|
428
|
this.crud = crud;
|
429
|
}
|
430
|
|
431
|
/**
|
432
|
* {@inheritDoc}
|
433
|
*/
|
434
|
@Override
|
435
|
public ICdmEntityUuidCacher getCache() {
|
436
|
return cache;
|
437
|
}
|
438
|
|
439
|
@Override
|
440
|
public void disposeCache() {
|
441
|
cache.dispose();
|
442
|
}
|
443
|
|
444
|
public void doCollectionEditorAdd(SpecimenTypeDesignationDTORow row) {
|
445
|
|
446
|
CollectionPopupEditor collectionPopupEditor = openPopupEditor(CollectionPopupEditor.class, null);
|
447
|
|
448
|
collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
449
|
collectionPopupEditor.withDeleteButton(true);
|
450
|
collectionPopupEditor.loadInEditor(null);
|
451
|
|
452
|
collectionPopupEditorsRowMap.put(collectionPopupEditor, row);
|
453
|
}
|
454
|
|
455
|
public void doCollectionEditorEdit(SpecimenTypeDesignationDTORow row) {
|
456
|
|
457
|
CollectionPopupEditor collectionPopupEditor = openPopupEditor(CollectionPopupEditor.class, null);
|
458
|
|
459
|
collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
460
|
collectionPopupEditor.withDeleteButton(true);
|
461
|
collectionPopupEditor.loadInEditor(row.collection.getValue().getUuid());
|
462
|
|
463
|
collectionPopupEditorsRowMap.put(collectionPopupEditor, row);
|
464
|
}
|
465
|
|
466
|
|
467
|
@EventBusListenerMethod(filter = EntityChangeEventFilter.OccurrenceCollectionFilter.class)
|
468
|
public void onCollectionEvent(EntityChangeEvent event){
|
469
|
|
470
|
if(event.getSourceView() instanceof AbstractPopupEditor) {
|
471
|
|
472
|
Stack<EditorActionContext> context = ((AbstractPopupEditor) event.getSourceView()).getEditorActionContext();
|
473
|
if(context.size() > 1){
|
474
|
AbstractView<?> parentView = context.get(context.size() - 2).getParentView();
|
475
|
if(getView().equals(parentView)){
|
476
|
Collection newCollection = getRepo().getCollectionService().load(
|
477
|
event.getEntityUuid(), Arrays.asList(new String[]{"$.institute"})
|
478
|
);
|
479
|
cache.load(newCollection);
|
480
|
|
481
|
if(event.isCreatedType()){
|
482
|
//TODO use typeDesignationsCollectionFieldHelper instead to get component
|
483
|
SpecimenTypeDesignationDTORow row = collectionPopupEditorsRowMap.get(event.getSourceView());
|
484
|
ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, SpecimenTypeDesignationDTORow.FIELD_INDEX_COLLECTION);
|
485
|
combobox.setValue((Collection) event.getEntity());
|
486
|
} else {
|
487
|
//TODO use typeDesignationsCollectionFieldHelper instead to get component
|
488
|
for( CollectionRowItemCollection row : typeDesignationEditorRows) {
|
489
|
ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, SpecimenTypeDesignationDTORow.FIELD_INDEX_COLLECTION);
|
490
|
combobox.reload();
|
491
|
}
|
492
|
}
|
493
|
}
|
494
|
}
|
495
|
}
|
496
|
}
|
497
|
|
498
|
public void doReferenceEditorAdd(ToOneRelatedEntityCombobox<Reference> referenceComobox) {
|
499
|
|
500
|
ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
|
501
|
|
502
|
String property = typeDesignationsCollectionFieldHelper.properyFor(referenceComobox);
|
503
|
if(property.equals(SpecimenTypeDesignationDTORow.FIELD_NAME_DESIGNATION_REFERENCE)){
|
504
|
referencePopupEditor.withReferenceTypes(EnumSet.of(ReferenceType.Section));
|
505
|
referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
506
|
referencePopupEditor.withDeleteButton(true);
|
507
|
RegistrationUiReferenceEditorFormConfigurator
|
508
|
.create(true).configure(referencePopupEditor, newReferenceInstantiator);
|
509
|
referencePopupEditor.loadInEditor(null);
|
510
|
} else {
|
511
|
// only other option by now
|
512
|
referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
|
513
|
referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
514
|
referencePopupEditor.withDeleteButton(true);
|
515
|
referencePopupEditor.loadInEditor(null);
|
516
|
}
|
517
|
|
518
|
referencePopupEditorsCombobox.put(referencePopupEditor, referenceComobox);
|
519
|
}
|
520
|
|
521
|
public void doReferenceEditorEdit(ToOneRelatedEntityCombobox<Reference> referenceComobox) {
|
522
|
|
523
|
ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
|
524
|
|
525
|
String property = typeDesignationsCollectionFieldHelper.properyFor(referenceComobox);
|
526
|
|
527
|
if(property.equals(SpecimenTypeDesignationDTORow.FIELD_NAME_DESIGNATION_REFERENCE)){
|
528
|
referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
529
|
referencePopupEditor.withDeleteButton(true);
|
530
|
RegistrationUiReferenceEditorFormConfigurator
|
531
|
.create(false).typeSelectReadonly(true).configure(referencePopupEditor, newReferenceInstantiator);
|
532
|
referencePopupEditor.loadInEditor(referenceComobox.getValue().getUuid());
|
533
|
} else {
|
534
|
// only other option by now
|
535
|
referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
|
536
|
referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
|
537
|
referencePopupEditor.withDeleteButton(true);
|
538
|
referencePopupEditor.loadInEditor(referenceComobox.getValue().getUuid());
|
539
|
}
|
540
|
|
541
|
referencePopupEditorsCombobox.put(referencePopupEditor, referenceComobox);
|
542
|
}
|
543
|
|
544
|
|
545
|
|
546
|
@EventBusListenerMethod(filter = EntityChangeEventFilter.ReferenceFilter.class)
|
547
|
public void onReferenceEvent(EntityChangeEvent event){
|
548
|
|
549
|
Reference newRef = getRepo().getReferenceService().load(event.getEntityUuid(), Arrays.asList(new String[]{"$"}));
|
550
|
cache.load(newRef);
|
551
|
|
552
|
ToOneRelatedEntityCombobox<Reference> combobox = referencePopupEditorsCombobox.get(event.getSourceView());
|
553
|
if(event.isCreatedType()){
|
554
|
combobox.setValue((Reference) event.getEntity());
|
555
|
} else {
|
556
|
for( CollectionRowItemCollection row : typeDesignationEditorRows) {
|
557
|
combobox.reload();
|
558
|
}
|
559
|
}
|
560
|
}
|
561
|
|
562
|
/**
|
563
|
* {@inheritDoc}
|
564
|
*/
|
565
|
@Override
|
566
|
public void addRootEntity(CdmBase entity) {
|
567
|
rootEntities.add(entity);
|
568
|
}
|
569
|
|
570
|
/**
|
571
|
* {@inheritDoc}
|
572
|
*/
|
573
|
@Override
|
574
|
public java.util.Collection<CdmBase> getRootEntities() {
|
575
|
return rootEntities ;
|
576
|
}
|
577
|
|
578
|
@Override
|
579
|
public void destroy() throws Exception {
|
580
|
super.destroy();
|
581
|
cache.dispose();
|
582
|
}
|
583
|
|
584
|
/**
|
585
|
* @return
|
586
|
* the {@link #publishedUnit}
|
587
|
*/
|
588
|
public NamedSourceBase getPublishedUnit() {
|
589
|
return publishedUnit;
|
590
|
}
|
591
|
|
592
|
/**
|
593
|
* @param publishedUnit
|
594
|
* The unit of publication in which the type designation has been published.
|
595
|
* This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
|
596
|
*/
|
597
|
protected void setPublishedUnit(NamedSourceBase publishedUnit) throws Exception {
|
598
|
if(publishedUnit == null) {
|
599
|
throw new NullPointerException();
|
600
|
}
|
601
|
if(publishedUnit.getCitation() == null) {
|
602
|
throw new NullPointerException("The citation of the published unit must not be null.");
|
603
|
}
|
604
|
if(!RegistrationUIDefaults.NOMECLATURAL_PUBLICATION_UNIT_TYPES.contains(publishedUnit.getCitation().getType())) {
|
605
|
throw new Exception("The referrence type '" + publishedUnit.getType() + "'is not allowed for publishedUnit.");
|
606
|
}
|
607
|
this.publishedUnit = publishedUnit;
|
608
|
}
|
609
|
|
610
|
@Override
|
611
|
public void setInTypedesignationOnlyAct(Optional<Boolean> isInTypedesignationOnlyAct) {
|
612
|
this.isInTypedesignationOnlyAct = isInTypedesignationOnlyAct;
|
613
|
}
|
614
|
|
615
|
@Override
|
616
|
public Optional<Boolean> isInTypedesignationOnlyAct() {
|
617
|
return isInTypedesignationOnlyAct;
|
618
|
}
|
619
|
|
620
|
}
|