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.Set;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.hibernate.Session;
|
15
|
import org.vaadin.viritin.fields.AbstractElementCollection;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.TermType;
|
18
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
19
|
import eu.etaxonomy.cdm.model.location.Country;
|
20
|
import eu.etaxonomy.cdm.model.name.Registration;
|
21
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
22
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
23
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
25
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
26
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
27
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
30
|
import eu.etaxonomy.cdm.vaadin.component.SelectFieldFactory;
|
31
|
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
|
32
|
import eu.etaxonomy.cdm.vaadin.model.registration.DerivationEventTypes;
|
33
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
34
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
35
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
|
36
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
37
|
/**
|
38
|
* SpecimenTypeDesignationWorkingsetPopupEditorView implementation must override the showInEditor() method,
|
39
|
* see {@link #prepareAsFieldGroupDataSource()} for details.
|
40
|
*
|
41
|
* @author a.kohlbecker
|
42
|
* @since Jun 13, 2017
|
43
|
*
|
44
|
*/
|
45
|
public class SpecimenTypeDesignationWorkingsetEditorPresenter
|
46
|
extends AbstractEditorPresenter<SpecimenTypeDesignationWorkingSetDTO , SpecimenTypeDesignationWorkingsetPopupEditorView> {
|
47
|
|
48
|
private static final long serialVersionUID = 4255636253714476918L;
|
49
|
|
50
|
|
51
|
/**
|
52
|
* {@inheritDoc}
|
53
|
*/
|
54
|
@SuppressWarnings("serial")
|
55
|
@Override
|
56
|
public void handleViewEntered() {
|
57
|
|
58
|
SelectFieldFactory selectFactory = new SelectFieldFactory(getRepo());
|
59
|
getView().getCountrySelectField().setContainerDataSource(selectFactory.buildBeanItemContainer(Country.uuidCountryVocabulary));
|
60
|
|
61
|
getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
|
62
|
|
63
|
CdmFilterablePagingProvider<Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection>(getRepo().getCollectionService());
|
64
|
|
65
|
CdmFilterablePagingProvider<Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference>(getRepo().getReferenceService());
|
66
|
|
67
|
@Override
|
68
|
public SpecimenTypeDesignationDTORow create() {
|
69
|
SpecimenTypeDesignationDTORow row = new SpecimenTypeDesignationDTORow();
|
70
|
|
71
|
row.typeStatus.setContainerDataSource(selectFactory.buildBeanItemContainer(TermType.SpecimenTypeDesignationStatus));
|
72
|
row.derivationEventType.setContainerDataSource(selectFactory.buildTermItemContainer(new UUID[]{
|
73
|
DerivationEventType.GATHERING_IN_SITU().getUuid(),
|
74
|
DerivationEventTypes.UNPUBLISHED_IMAGE().getUuid(),
|
75
|
DerivationEventTypes.PUBLISHED_IMAGE().getUuid(),
|
76
|
DerivationEventTypes.CULTURE_METABOLIC_INACTIVE().getUuid()
|
77
|
}));
|
78
|
|
79
|
row.collection.loadFrom(collectionPagingProvider, collectionPagingProvider, collectionPagingProvider.getPageSize());
|
80
|
row.collection.getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Collection>());
|
81
|
|
82
|
row.mediaSpecimenReference.loadFrom(referencePagingProvider, referencePagingProvider, collectionPagingProvider.getPageSize());
|
83
|
row.mediaSpecimenReference.getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
|
84
|
|
85
|
getView().applyDefaultComponentStyle(row.components());
|
86
|
return row;
|
87
|
}
|
88
|
|
89
|
});
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* {@inheritDoc}
|
94
|
*
|
95
|
* see also {@link SpecimenTypeDesignationWorkingsetPopupEditor#showInEditor()}
|
96
|
*/
|
97
|
@Override
|
98
|
protected SpecimenTypeDesignationWorkingSetDTO prepareAsFieldGroupDataSource(SpecimenTypeDesignationWorkingSetDTO bean) {
|
99
|
if(bean.getFieldUnit() == null){
|
100
|
// in case the base unit of the working set is not a FieldUnit all contained TypeDesignations must be modified
|
101
|
// so that they are based on an empty FieldUnit with an associated Gathering Event
|
102
|
if(Registration.class.isAssignableFrom(bean.getOwner().getClass())){
|
103
|
// FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
|
104
|
logger.info("Basing all typeDesignations on a new fieldUnit");
|
105
|
Session session = getSession();
|
106
|
Registration reg = getRepo().getRegistrationService().find(bean.getOwner().getId());
|
107
|
RegistrationDTO regDTO = new RegistrationDTO(reg);
|
108
|
|
109
|
FieldUnit fieldUnit = FieldUnit.NewInstance();
|
110
|
GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
|
111
|
fieldUnit.setGatheringEvent(gatheringEvent);
|
112
|
getRepo().getOccurrenceService().save(fieldUnit);
|
113
|
|
114
|
VersionableEntity baseEntity = bean.getBaseEntity();
|
115
|
Set<TypeDesignationBase> typeDesignations = regDTO.getTypeDesignationsInWorkingSet(
|
116
|
new TypedEntityReference(baseEntity.getClass(), baseEntity.getId(), baseEntity.toString())
|
117
|
);
|
118
|
for(TypeDesignationBase td : typeDesignations){
|
119
|
DerivationEvent de = DerivationEvent.NewInstance();//
|
120
|
de.addOriginal(fieldUnit);
|
121
|
de.addDerivative(((SpecimenTypeDesignation)td).getTypeSpecimen());
|
122
|
de.setType(DerivationEventType.GATHERING_IN_SITU());
|
123
|
}
|
124
|
|
125
|
getRepo().getRegistrationService().saveOrUpdate(reg);
|
126
|
session.flush();
|
127
|
session.close();
|
128
|
} else {
|
129
|
throw new RuntimeException("Usupported owner type " + bean.getOwner().getClass() + ", needs to be implemented.");
|
130
|
}
|
131
|
}
|
132
|
return super.prepareAsFieldGroupDataSource(bean);
|
133
|
}
|
134
|
|
135
|
|
136
|
|
137
|
/**
|
138
|
* {@inheritDoc}
|
139
|
*/
|
140
|
@Override
|
141
|
protected void saveBean(SpecimenTypeDesignationWorkingSetDTO bean) {
|
142
|
// TODO Auto-generated method stub
|
143
|
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* {@inheritDoc}
|
148
|
*/
|
149
|
@Override
|
150
|
protected void deleteBean(SpecimenTypeDesignationWorkingSetDTO bean) {
|
151
|
// TODO Auto-generated method stub
|
152
|
|
153
|
}
|
154
|
|
155
|
|
156
|
}
|