Project

General

Profile

Download (3.73 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.persistence.dao.hibernate.taxonGraph;
10

    
11
import java.util.EnumSet;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.apache.log4j.Logger;
16
import org.hibernate.Session;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.stereotype.Repository;
19
import org.springframework.transaction.annotation.Transactional;
20

    
21
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.model.reference.ReferenceType;
27
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
28
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
29
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
30
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
31
import eu.etaxonomy.cdm.persistence.dao.taxonGraph.ITaxonGraphDao;
32
import eu.etaxonomy.cdm.persistence.dao.taxonGraph.TaxonGraphException;
33
import eu.etaxonomy.cdm.persistence.dto.TaxonGraphEdgeDTO;
34

    
35
/**Ta
36
 * Provides the business logic to manage multiple classifications as
37
 * classification fragments in a graph of
38
 * {@link eu.etaxonomy.cdm.model.taxon.Taxon Taxa} and {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationship TaxonRelationships}.
39
 *
40
 * For further details on the concept and related discussion see https://dev.e-taxonomy.eu/redmine/issues/6173
41
 *
42
 *
43
 * @author a.kohlbecker
44
 * @since Sep 26, 2018
45
 *
46
 */
47
@Repository("taxonGraphDao")
48
@Transactional(readOnly = true)
49
public class TaxonGraphDaoHibernateImpl extends AbstractHibernateTaxonGraphProcessor implements ITaxonGraphDao {
50

    
51
    private TaxonRelationshipType relType = TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
52

    
53
    private EnumSet<ReferenceType> referenceSectionTypes = EnumSet.of(ReferenceType.Section, ReferenceType.BookSection);
54

    
55
    private static final Logger logger = Logger.getLogger(TaxonGraphDaoHibernateImpl.class);
56

    
57
    public static final PrefKey CDM_PREF_KEY_SEC_REF_UUID = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.TaxonGraphSecRefUuid);
58

    
59
    @Autowired
60
    private ITaxonDao taxonDao;
61

    
62
    @Autowired
63
    private IReferenceDao referenceDao;
64

    
65
    @Autowired
66
    private ITaxonNameDao nameDao;
67

    
68
    private UUID secReferenceUUID;
69

    
70
    protected TaxonRelationshipType relType() {
71
        if(relType == null){
72
            relType = TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
73
        }
74
        return relType;
75
    }
76

    
77
    @Override
78
    public List<TaxonGraphEdgeDTO> edges(TaxonName fromName, TaxonName toName, boolean includeUnpublished) throws TaxonGraphException{
79
        UUID fromTaxonUUID = null;
80
        UUID toTaxonUUID = null;
81
        if(fromName != null){
82
            fromTaxonUUID = assureSingleTaxon(fromName).getUuid();
83
        }
84
        if(toName != null){
85
            toTaxonUUID = assureSingleTaxon(toName).getUuid();
86
        }
87
        return taxonDao.listTaxonGraphEdgeDTOs(fromTaxonUUID, toTaxonUUID, relType(), includeUnpublished, null, null);
88
    }
89

    
90
    @Override
91
    public List<TaxonGraphEdgeDTO> edges(UUID fromtaxonUuid, UUID toTaxonUuid, boolean includeUnpublished) throws TaxonGraphException{
92
        return taxonDao.listTaxonGraphEdgeDTOs(fromtaxonUuid, toTaxonUuid, relType(), includeUnpublished, null, null);
93
    }
94

    
95
    /**
96
     * {@inheritDoc}
97
     */
98
    @Override
99
    Session getSession() {
100
        return taxonDao.getSession();
101
    }
102

    
103

    
104
}
(4-4/4)