Project

General

Profile

Download (4.57 KB) Statistics
| Branch: | Tag: | Revision:
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.location.Country;
17
import eu.etaxonomy.cdm.model.name.Registration;
18
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
19
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
20
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
21
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
22
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
23
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
24
import eu.etaxonomy.cdm.vaadin.component.SelectFieldFactory;
25
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
26
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
27
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO;
28
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
29

    
30
/**
31
 * SpecimenTypeDesignationWorkingsetPopupEditorView implementation must override the showInEditor() method,
32
 * see {@link #prepareAsFieldGroupDataSource()} for details.
33
 *
34
 * @author a.kohlbecker
35
 * @since Jun 13, 2017
36
 *
37
 */
38
public class SpecimenTypeDesignationWorkingsetEditorPresenter
39
    extends AbstractEditorPresenter<SpecimenTypeDesignationWorkingSetDTO , SpecimenTypeDesignationWorkingsetPopupEditorView> {
40

    
41
    private static final long serialVersionUID = 4255636253714476918L;
42

    
43

    
44
    /**
45
     * {@inheritDoc}
46
     */
47
    @Override
48
    public void handleViewEntered() {
49
        SelectFieldFactory selectFactory = new SelectFieldFactory(getRepo());
50
        getView().getCountrySelectField().setContainerDataSource(selectFactory.buildBeanItemContainer(Country.uuidCountryVocabulary));
51
    }
52

    
53
    /**
54
     * {@inheritDoc}
55
     *
56
     * see also {@link SpecimenTypeDesignationWorkingsetPopupEditor#showInEditor()}
57
     */
58
    @Override
59
    protected SpecimenTypeDesignationWorkingSetDTO prepareAsFieldGroupDataSource(SpecimenTypeDesignationWorkingSetDTO bean) {
60
        if(bean.getFieldUnit() == null){
61
            // in case the base unit of the working set is not a FieldUnit all contained TypeDesignations must be modified
62
            // so that they are based on an empty FieldUnit with an associated Gathering Event
63
            if(Registration.class.isAssignableFrom(bean.getOwner().getClass())){
64
                // FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
65
                logger.info("Basing all typeDesignations on a new fieldUnit");
66
                Session session = getSession();
67
                Registration reg = getRepo().getRegistrationService().find(bean.getOwner().getId());
68
                RegistrationDTO regDTO = new RegistrationDTO(reg);
69

    
70
                FieldUnit fieldUnit = FieldUnit.NewInstance();
71
                GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
72
                fieldUnit.setGatheringEvent(gatheringEvent);
73
                getRepo().getOccurrenceService().save(fieldUnit);
74

    
75
                VersionableEntity baseEntity = bean.getBaseEntity();
76
                Set<TypeDesignationBase> typeDesignations = regDTO.getTypeDesignationsInWorkingSet(
77
                        new TypedEntityReference(baseEntity.getClass(), baseEntity.getId(), baseEntity.toString())
78
                        );
79
                for(TypeDesignationBase td : typeDesignations){
80
                    DerivationEvent de = DerivationEvent.NewInstance();//
81
                    de.addOriginal(fieldUnit);
82
                    de.addDerivative(((SpecimenTypeDesignation)td).getTypeSpecimen());
83
                    de.setType(DerivationEventType.GATHERING_IN_SITU());
84
                }
85

    
86
                getRepo().getRegistrationService().saveOrUpdate(reg);
87
                session.flush();
88
                session.close();
89
            } else {
90
                throw new RuntimeException("Usupported owner type " + bean.getOwner().getClass() + ", needs to be implemented.");
91
            }
92
        }
93
        return super.prepareAsFieldGroupDataSource(bean);
94
    }
95

    
96

    
97

    
98
    /**
99
     * {@inheritDoc}
100
     */
101
    @Override
102
    protected void saveBean(SpecimenTypeDesignationWorkingSetDTO bean) {
103
        // TODO Auto-generated method stub
104

    
105
    }
106

    
107
    /**
108
     * {@inheritDoc}
109
     */
110
    @Override
111
    protected void deleteBean(SpecimenTypeDesignationWorkingSetDTO bean) {
112
        // TODO Auto-generated method stub
113

    
114
    }
115

    
116

    
117
}
(1-1/6)