Project

General

Profile

Download (2.88 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.taxeditor.editor.workingSet.matrix;
10

    
11
import java.util.Collection;
12

    
13
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
16
import eu.etaxonomy.cdm.model.location.NamedArea;
17
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
18
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
19
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 * @author pplitzner
27
 * @since Dec 14, 2017
28
 *
29
 */
30
public class RowWrapper {
31

    
32
    private SpecimenDescription description;
33

    
34
    private Taxon associatedTaxon;
35
    private FieldUnit fieldUnit;
36
    private String identifier;
37
    private NamedArea country;
38

    
39
    public RowWrapper(SpecimenDescription description) {
40
        this.description = description;
41

    
42
        IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
43
        SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class);
44
        if(specimen!=null){
45
            Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
46
            if(associatedTaxa!=null){
47
                associatedTaxon = (Taxon) associatedTaxa.iterator().next();
48
            }
49
            Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid());
50
            if(fieldUnits.size()!=1){
51
                MessagingUtils.error(RowWrapper.class, "More than one or no field unit found for specimen", null);
52
            }
53
            else{
54
                fieldUnit = fieldUnits.iterator().next();
55
            }
56
            if(specimen instanceof DerivedUnit){
57
                identifier = occurrenceService.getMostSignificantIdentifier(HibernateProxyHelper.deproxy(specimen, DerivedUnit.class));
58
            }
59
            if(fieldUnit!=null && fieldUnit.getGatheringEvent()!=null){
60
                country = fieldUnit.getGatheringEvent().getCountry();
61
            }
62
        }
63
    }
64

    
65
    public SpecimenDescription getSpecimenDescription() {
66
        return description;
67
    }
68

    
69
    public Taxon getAssociatedTaxon() {
70
        return associatedTaxon;
71
    }
72

    
73
    public FieldUnit getFieldUnit() {
74
        return fieldUnit;
75
    }
76

    
77
    public String getIdentifier() {
78
        return identifier;
79
    }
80

    
81
    public NamedArea getCountry() {
82
        return country;
83
    }
84

    
85
}
(8-8/11)