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
|
|
13
|
import org.hibernate.Session;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
16
|
import eu.etaxonomy.cdm.model.name.Registration;
|
17
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
18
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
19
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
22
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
23
|
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
|
24
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
25
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
|
26
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
27
|
|
28
|
/**
|
29
|
* SpecimenTypeDesignationWorkingsetPopupEditorView implementation must override the showInEditor() method,
|
30
|
* see {@link #prepareAsFieldGroupDataSource()} for details.
|
31
|
*
|
32
|
* @author a.kohlbecker
|
33
|
* @since Jun 13, 2017
|
34
|
*
|
35
|
*/
|
36
|
public class SpecimenTypeDesignationWorkingsetEditorPresenter
|
37
|
extends AbstractEditorPresenter<SpecimenTypeDesignationWorkingSetDTO , SpecimenTypeDesignationWorkingsetPopupEditorView> {
|
38
|
|
39
|
private static final long serialVersionUID = 4255636253714476918L;
|
40
|
private Registration registration;
|
41
|
|
42
|
|
43
|
|
44
|
|
45
|
/**
|
46
|
* {@inheritDoc}
|
47
|
*
|
48
|
* see also {@link SpecimenTypeDesignationWorkingsetPopupEditor#showInEditor()}
|
49
|
*/
|
50
|
@Override
|
51
|
protected SpecimenTypeDesignationWorkingSetDTO prepareAsFieldGroupDataSource(SpecimenTypeDesignationWorkingSetDTO bean) {
|
52
|
if(bean.getFieldUnit() == null){
|
53
|
// in case the base unit of the working set is not a FieldUnit all contained TypeDesignations must be modified
|
54
|
// so that they are based on an empty FieldUnit with an associated Gathering Event
|
55
|
if(Registration.class.isAssignableFrom(bean.getOwner().getClass())){
|
56
|
// FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
|
57
|
logger.info("Basing all typeDesignations on a new fieldUnit");
|
58
|
Session session = getSession();
|
59
|
Registration reg = getRepo().getRegistrationService().find(bean.getOwner().getId());
|
60
|
RegistrationDTO regDTO = new RegistrationDTO(reg);
|
61
|
|
62
|
FieldUnit fieldUnit = FieldUnit.NewInstance();
|
63
|
GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
|
64
|
fieldUnit.setGatheringEvent(gatheringEvent);
|
65
|
getRepo().getOccurrenceService().save(fieldUnit);
|
66
|
|
67
|
VersionableEntity baseEntity = bean.getBaseEntity();
|
68
|
Set<TypeDesignationBase> typeDesignations = regDTO.getTypeDesignationsInWorkingSet(
|
69
|
new TypedEntityReference(baseEntity.getClass(), baseEntity.getId(), baseEntity.toString())
|
70
|
);
|
71
|
for(TypeDesignationBase td : typeDesignations){
|
72
|
DerivationEvent de = DerivationEvent.NewInstance();//
|
73
|
de.addOriginal(fieldUnit);
|
74
|
de.addDerivative(((SpecimenTypeDesignation)td).getTypeSpecimen());
|
75
|
de.setType(DerivationEventType.GATHERING_IN_SITU());
|
76
|
}
|
77
|
|
78
|
getRepo().getRegistrationService().saveOrUpdate(reg);
|
79
|
session.flush();
|
80
|
session.close();
|
81
|
} else {
|
82
|
throw new RuntimeException("Usupported owner type " + bean.getOwner().getClass() + ", needs to be implemented.");
|
83
|
}
|
84
|
}
|
85
|
return super.prepareAsFieldGroupDataSource(bean);
|
86
|
}
|
87
|
|
88
|
|
89
|
|
90
|
/**
|
91
|
* {@inheritDoc}
|
92
|
*/
|
93
|
@Override
|
94
|
protected void saveBean(SpecimenTypeDesignationWorkingSetDTO bean) {
|
95
|
// TODO Auto-generated method stub
|
96
|
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* {@inheritDoc}
|
101
|
*/
|
102
|
@Override
|
103
|
protected void deleteBean(SpecimenTypeDesignationWorkingSetDTO bean) {
|
104
|
// TODO Auto-generated method stub
|
105
|
|
106
|
}
|
107
|
|
108
|
|
109
|
}
|