Project

General

Profile

Revision 4e5c4e73

ID4e5c4e73f5de867e0bb67066ab672a2d9bd4352c
Parent c27ce9cc
Child 810bbc08

Added by Andreas Müller 12 months ago

cleanup and ref #6794 rename TermTreeDaoImpl

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermTree.java
152 152
	protected TermTree(TermType termType) {
153 153
        super(termType);
154 154
		root = new TermTreeNode<>(termType);
155
		root.setGraph((TermTree)this);
155
		root.setGraph(this);
156 156
	}
157 157

  
158 158
// ****************** GETTER / SETTER **********************************/
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IFeatureTreeDao.java
12 12
import java.util.List;
13 13
import java.util.UUID;
14 14

  
15
import eu.etaxonomy.cdm.model.term.TermTreeNode;
16 15
import eu.etaxonomy.cdm.model.term.TermTree;
16
import eu.etaxonomy.cdm.model.term.TermTreeNode;
17 17
import eu.etaxonomy.cdm.model.term.TermType;
18 18
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
19 19
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
......
21 21
/**
22 22
 * @author a.mueller
23 23
 * @since 10.07.2008
24
 * @version 1.0
25 24
 */
26 25
public interface IFeatureTreeDao extends IIdentifiableDao<TermTree> {
26

  
27 27
    public List<TermTree> list();
28 28

  
29 29
    public UUID DefaultFeatureTreeUuid = UUID.fromString("ac8d4e58-926d-4f81-ac77-cebdd295df7c");
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/FeatureDaoImpl.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
26 26
	private static final Logger logger = Logger.getLogger(FeatureDaoImpl.class);
27 27

  
28 28
	public FeatureDaoImpl() {
29
		super(Feature.class); 
29
		super(Feature.class);
30 30
	}
31
	
32
	public List<Feature> list() {
33
		Criteria crit = getSession().createCriteria(type); 
34
		return crit.list(); 
31

  
32
	@Override
33
    public List<Feature> list() {
34
		Criteria crit = getSession().createCriteria(type);
35
		@SuppressWarnings("unchecked")
36
	    List<Feature> result = crit.list();
37
		return result;
35 38
	}
36 39
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/FeatureTreeDaoImpl.java
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.apache.log4j.Logger;
17
import org.hibernate.Criteria;
18
import org.hibernate.Query;
19
import org.hibernate.Session;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Repository;
22

  
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.term.TermTreeNode;
25
import eu.etaxonomy.cdm.model.term.TermTree;
26
import eu.etaxonomy.cdm.model.term.TermType;
27
import eu.etaxonomy.cdm.model.term.TermVocabulary;
28
import eu.etaxonomy.cdm.model.term.VocabularyEnum;
29
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
30
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
31
import eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao;
32
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
33

  
34
/**
35
 * @author a.mueller
36
 * @since 10.07.2008
37
 * @version 1.0
38
 */
39
@Repository
40
public class FeatureTreeDaoImpl extends IdentifiableDaoBase<TermTree> implements IFeatureTreeDao{
41
    @SuppressWarnings("unused")
42
    private static final Logger logger = Logger.getLogger(FeatureTreeDaoImpl.class);
43

  
44
    @Autowired
45
    private ITermVocabularyDao termVocabularyDao;
46

  
47
    public FeatureTreeDaoImpl() {
48
        super(TermTree.class);
49
        indexedClasses = new Class[1];
50
        indexedClasses[0] = TermTree.class;
51
//		indexedClasses[1] = PolytomousKey.class;
52
    }
53

  
54
    @Override
55
    public List<TermTree> list() {
56
        Criteria crit = getSession().createCriteria(type);
57
        return crit.list();
58
    }
59

  
60
    @Override
61
    public void deepLoadNodes(List<TermTreeNode> nodes, List<String> nodePaths) {
62

  
63
        defaultBeanInitializer.initializeAll(nodes, nodePaths);
64

  
65
        List<TermTreeNode> childrenOfChildren = new ArrayList<TermTreeNode>();
66
        for(TermTreeNode node : nodes) {
67
            if(node.getChildCount() > 0){
68
                childrenOfChildren.addAll(node.getChildNodes());
69
            }
70
        }
71
        if(childrenOfChildren.size() > 0){
72
            deepLoadNodes(childrenOfChildren, nodePaths);
73
        }
74
    }
75

  
76
    @Override
77
    public TermTree load(UUID uuid, List<String> propertyPaths) {
78
        if (uuid.equals(DefaultFeatureTreeUuid) || count() == 0){
79
            return createDefaultFeatureTree();
80
        }
81
        return super.load(uuid, propertyPaths);
82
    }
83

  
84
    @Override
85
    public TermTree load(UUID uuid) {
86
        if (uuid.equals(DefaultFeatureTreeUuid) || count() == 0){
87
            return createDefaultFeatureTree();
88
        }
89
        return super.load(uuid);
90
    }
91

  
92
    /**
93
     *
94
     */
95
    private TermTree createDefaultFeatureTree() {
96

  
97
        TermVocabulary featureVocabulary = termVocabularyDao.findByUuid(VocabularyEnum.Feature.getUuid());
98

  
99
        List<Feature> featureList = new ArrayList<Feature>(featureVocabulary.getTerms());
100
        List<Feature> selectedFeatures = new ArrayList<Feature>();
101
        for(Feature feature : featureList){
102
            if(!feature.equals(Feature.INDIVIDUALS_ASSOCIATION())){
103
                selectedFeatures.add(feature);
104
            }
105
        }
106
        TermTree featureTree = TermTree.NewInstance(selectedFeatures);
107
        featureTree.setUuid(DefaultFeatureTreeUuid);
108
        return featureTree;
109
    }
110

  
111
    @Override
112
    public <S extends TermTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
113
            String pattern) {
114
        Session session = getSession();
115
        Query query = session.createQuery(
116
                " SELECT uuid, id, titleCache "
117
                        + " FROM " + clazz.getSimpleName()
118
                        + (pattern!=null?" WHERE titleCache LIKE :pattern":" WHERE 1 = 1 ")
119
                        + (termType!=null?" AND termType = :termType ":"")
120
                );
121
        if(pattern!=null){
122
            pattern = pattern.replace("*", "%");
123
            pattern = pattern.replace("?", "_");
124
            pattern = pattern + "%";
125
            query.setParameter("pattern", pattern);
126
        }
127
        if(termType!=null){
128
            query.setParameter("termType", termType);
129
        }
130
        if (limit != null){
131
           query.setMaxResults(limit);
132
        }
133
        return getUuidAndTitleCache(query);
134
    }
135

  
136

  
137
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/TermTreeDaoImpl.java
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.apache.log4j.Logger;
17
import org.hibernate.Criteria;
18
import org.hibernate.Query;
19
import org.hibernate.Session;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Repository;
22

  
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.term.TermTree;
25
import eu.etaxonomy.cdm.model.term.TermTreeNode;
26
import eu.etaxonomy.cdm.model.term.TermType;
27
import eu.etaxonomy.cdm.model.term.TermVocabulary;
28
import eu.etaxonomy.cdm.model.term.VocabularyEnum;
29
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
30
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
31
import eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao;
32
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
33

  
34
/**
35
 * @author a.mueller
36
 * @since 10.07.2008
37
 */
38
@Repository
39
public class TermTreeDaoImpl extends IdentifiableDaoBase<TermTree> implements IFeatureTreeDao{
40

  
41
    @SuppressWarnings("unused")
42
    private static final Logger logger = Logger.getLogger(TermTreeDaoImpl.class);
43

  
44
    @Autowired
45
    private ITermVocabularyDao termVocabularyDao;
46

  
47
    public TermTreeDaoImpl() {
48
        super(TermTree.class);
49
        indexedClasses = new Class[1];
50
        indexedClasses[0] = TermTree.class;
51
    }
52

  
53
    @Override
54
    public List<TermTree> list() {
55
        Criteria crit = getSession().createCriteria(type);
56
        return crit.list();
57
    }
58

  
59
    @Override
60
    public void deepLoadNodes(List<TermTreeNode> nodes, List<String> nodePaths) {
61

  
62
        defaultBeanInitializer.initializeAll(nodes, nodePaths);
63

  
64
        List<TermTreeNode> childrenOfChildren = new ArrayList<>();
65
        for(TermTreeNode node : nodes) {
66
            if(node.getChildCount() > 0){
67
                childrenOfChildren.addAll(node.getChildNodes());
68
            }
69
        }
70
        if(childrenOfChildren.size() > 0){
71
            deepLoadNodes(childrenOfChildren, nodePaths);
72
        }
73
    }
74

  
75
    @Override
76
    public TermTree load(UUID uuid, List<String> propertyPaths) {
77
        if (uuid.equals(DefaultFeatureTreeUuid) || count() == 0){
78
            return createDefaultFeatureTree();
79
        }
80
        return super.load(uuid, propertyPaths);
81
    }
82

  
83
    @Override
84
    public TermTree load(UUID uuid) {
85
        if (uuid.equals(DefaultFeatureTreeUuid) || count() == 0){
86
            return createDefaultFeatureTree();
87
        }
88
        return super.load(uuid);
89
    }
90

  
91
    private TermTree createDefaultFeatureTree() {
92

  
93
        TermVocabulary featureVocabulary = termVocabularyDao.findByUuid(VocabularyEnum.Feature.getUuid());
94

  
95
        List<Feature> featureList = new ArrayList<>(featureVocabulary.getTerms());
96
        List<Feature> selectedFeatures = new ArrayList<>();
97
        for(Feature feature : featureList){
98
            if(!feature.equals(Feature.INDIVIDUALS_ASSOCIATION())){
99
                selectedFeatures.add(feature);
100
            }
101
        }
102
        TermTree featureTree = TermTree.NewInstance(selectedFeatures);
103
        featureTree.setUuid(DefaultFeatureTreeUuid);
104
        return featureTree;
105
    }
106

  
107
    @Override
108
    public <S extends TermTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
109
            String pattern) {
110
        Session session = getSession();
111
        Query query = session.createQuery(
112
                " SELECT uuid, id, titleCache "
113
                        + " FROM " + clazz.getSimpleName()
114
                        + (pattern!=null?" WHERE titleCache LIKE :pattern":" WHERE 1 = 1 ")
115
                        + (termType!=null?" AND termType = :termType ":"")
116
                );
117
        if(pattern!=null){
118
            pattern = pattern.replace("*", "%");
119
            pattern = pattern.replace("?", "_");
120
            pattern = pattern + "%";
121
            query.setParameter("pattern", pattern);
122
        }
123
        if(termType!=null){
124
            query.setParameter("termType", termType);
125
        }
126
        if (limit != null){
127
           query.setMaxResults(limit);
128
        }
129
        return getUuidAndTitleCache(query);
130
    }
131

  
132

  
133
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/initializer/AbstractBeanInitializer.java
58 58
        return beanAutoInitializers;
59 59
    }
60 60

  
61
    /* (non-Javadoc)
62
     * @see eu.etaxonomy.cdm.persistence.dao.BeanInitializer#initializeInstance(java.lang.Object)
63
     */
64 61
    @Override
65 62
    public abstract Object initializeInstance(Object proxy);
66 63

  
67
    /* (non-Javadoc)
68
     * @see eu.etaxonomy.cdm.persistence.dao.BeanInitializer#load(eu.etaxonomy.cdm.model.common.CdmBase)
69
     */
70 64
    @Override
71 65
    public void load(Object bean) {
72 66
        initializeBean(bean, true, false);
73 67
    }
74 68

  
75
    /* (non-Javadoc)
76
     * @see eu.etaxonomy.cdm.persistence.dao.BeanInitializer#loadFully(eu.etaxonomy.cdm.model.common.CdmBase)
77
     */
78 69
    @Override
79 70
    public void loadFully(Object bean) {
80 71
        initializeBean(bean, true, true);
......
95 86
    public void initializeBean(Object bean, boolean cdmEntities, boolean collections){
96 87

  
97 88
        if(logger.isDebugEnabled()){logger.debug(">> starting wildcard initializeBean() of " + bean + " ;class:" + bean.getClass().getSimpleName()); }
98
        Set<Class<?>> restrictions = new HashSet<Class<?>>();
89
        Set<Class<?>> restrictions = new HashSet<>();
99 90
        if(cdmEntities){
100 91
            restrictions.add(CdmBase.class);
101 92
        }
......
121 112
        }
122 113
    }
123 114

  
124
    /* (non-Javadoc)
125
     * @see eu.etaxonomy.cdm.persistence.dao.BeanInitializer#initializeProperties(java.lang.Object, java.util.List)
126
     */
127 115
    //TODO optimize algorithm ..
128 116
    @Override
129 117
    public void initialize(Object bean, List<String> propertyPaths) {
......
396 384
     */
397 385
    public static Set<PropertyDescriptor> getProperties(Object bean, Set<Class<?>> typeRestrictions) {
398 386

  
399
        Set<PropertyDescriptor> properties = new HashSet<PropertyDescriptor>();
387
        Set<PropertyDescriptor> properties = new HashSet<>();
400 388
        PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(bean);
401 389

  
402 390
        for (PropertyDescriptor prop : props) {
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/FeatureTreeServiceImpl.java
25 25
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
26 26
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
27 27
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28
import eu.etaxonomy.cdm.model.term.TermTreeNode;
29 28
import eu.etaxonomy.cdm.model.term.TermTree;
29
import eu.etaxonomy.cdm.model.term.TermTreeNode;
30 30
import eu.etaxonomy.cdm.model.term.TermType;
31
import eu.etaxonomy.cdm.persistence.dao.description.ITermTreeNodeDao;
32 31
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
32
import eu.etaxonomy.cdm.persistence.dao.description.ITermTreeNodeDao;
33 33
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
34 34
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
35 35

  
......
88 88
            nodePaths.add("children");
89 89
        }
90 90

  
91
        List<String> rootPaths = new ArrayList<String>();
91
        List<String> rootPaths = new ArrayList<>();
92 92
        rootPaths.add("root");
93 93
        for(String path : nodePaths) {
94 94
            rootPaths.add("root." + path);
......
102 102
        if(featureTree == null){
103 103
            throw new EntityNotFoundException("No FeatureTree entity found for " + uuid);
104 104
        }
105
        dao.deepLoadNodes(featureTree.getRoot().getChildNodes() ,nodePaths);
105
        dao.deepLoadNodes(featureTree.getRoot().getChildNodes(), nodePaths);
106 106
        return featureTree;
107 107
    }
108 108

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/FeatureNodeServiceImplTest.java
81 81

  
82 82
		featureNodeService.saveOrUpdate(newNode);
83 83

  
84
		commitAndStartNewTransaction(new String[]{"FeatureNode"});
84
		commitAndStartNewTransaction(/*new String[]{"FeatureNode"}*/);
85 85
		newNode = featureNodeService.load(newNode.getUuid());
86 86
		Assert.assertEquals("", sep + pref+featureTree.getId()+sep + featureTree.getRoot().getId()+ sep  + newNode.getId() + sep, newNode.treeIndex());
87 87
	}
......
145 145
	@DataSet(value="FeatureNodeServiceImplTest-indexing.xml")
146 146
	public final void testIndexDeleteNode() {
147 147
		node2 = featureNodeService.load(node2Uuid);
148
		TermTreeNode root = node2.getParent();
148
		TermTreeNode<Feature> root = node2.getParent();
149 149
		FeatureNodeDeletionConfigurator config = new FeatureNodeDeletionConfigurator();
150 150
		config.setDeleteElement(false);
151 151
        config.setChildHandling(ChildHandling.MOVE_TO_PARENT);
152 152
        DeleteResult result = featureNodeService.deleteFeatureNode(node2Uuid, config);
153 153
        commitAndStartNewTransaction(new String[]{"TaxonNode"});
154
        TermTree tree1 = featureTreeService.load(featureTreeUuid);
154
        TermTree<Feature> tree1 = featureTreeService.load(featureTreeUuid);
155 155
        assertNotNull(tree1);
156 156
        node2 = featureNodeService.load(node2Uuid);
157 157
        assertNull(node2);
cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/unitils/CleanSweepInsertLoadStrategy.java
24 24
import org.unitils.util.FileUtils;
25 25

  
26 26
/**
27
 * will clear all data in the DataSet except all term related tables
27
 * Will clear all data in the DataSet except all term related tables
28 28
   before doing a CLEAN_INSERT:
29 29
 * @author Andreas Kohlbecker
30
 *
31 30
 */
32 31
public class CleanSweepInsertLoadStrategy extends CleanInsertLoadStrategy {
33 32

  
......
51 50
        // before doing a CLEAN_INSERT:
52 51
        MultiSchemaDataSet multiSchemaDataset = null;
53 52
        URL fileUrl = null;
53
        MultiSchemaXmlDataSetFactory dataSetFactory = new MultiSchemaXmlDataSetFactory();
54
        fileUrl = getClass().getClassLoader().getResource(clearDataResource);
55
        if (fileUrl == null) {
56
            throw new RuntimeException("the Resource " + clearDataResource + " could not be found");
57
        }
54 58
        try {
55
            MultiSchemaXmlDataSetFactory dataSetFactory = new MultiSchemaXmlDataSetFactory();
56
            fileUrl = getClass().getClassLoader().getResource(clearDataResource);
57
            if (fileUrl == null) {
58
                throw new IOException("the Resource " + clearDataResource + " could not be found");
59
            }
60 59
            File file;
61 60
            logger.debug("fileUrl:" + fileUrl.toString() + "; protocol: " +  fileUrl.getProtocol());
62 61
            if(fileUrl.toString().startsWith("jar:file:")){
......
72 71
        }
73 72

  
74 73
        if(multiSchemaDataset != null){
75
               for (String name : multiSchemaDataset.getSchemaNames()) {
74
            for (String name : multiSchemaDataset.getSchemaNames()) {
76 75
                IDataSet clearDataSet = multiSchemaDataset.getDataSetForSchema(name);
77 76
                logger.debug("doing CLEAN_INSERT with dataset '" + name + "'");
78 77
                DatabaseOperation.CLEAN_INSERT.execute(dbUnitDatabaseConnection, clearDataSet);
cdmlib-test/src/main/resources/unitils.properties
98 98
#    'TERMVOCABULARY_REPRESENTATION_AUD'  but hibernate expects CamelCase with mysql !!!!
99 99
#    maybe we can workaround this by implementing a custom EJB3NamingStrategy like
100 100
#    UppercaseTableNamingStrategy it must be set in the persitence.xml which returns table names
101
#    always in uppercase, but this again causes problems with the @Tabel annotations which must
101
#    always in uppercase, but this again causes problems with the @Table annotations which must
102 102
#    exactly match the table names in the database. This means in order to use mysql for tests we would
103 103
#    have to change the table names in all of our DataSet files.
104 104
#

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)