Project

General

Profile

Revision e793a739

IDe793a739b3cb36b129146cff5439650274019f31
Parent cf862eed
Child 0d80c92f

Added by Andreas Müller 12 months ago

ref #6794 update some imports to model changes and add ITermTree

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/in/StructureTreeOwlImport.java
20 20

  
21 21
import eu.etaxonomy.cdm.io.common.CdmImportBase;
22 22
import eu.etaxonomy.cdm.io.descriptive.owl.OwlUtil;
23
import eu.etaxonomy.cdm.model.description.Feature;
23 24
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
24
import eu.etaxonomy.cdm.model.term.FeatureNode;
25
import eu.etaxonomy.cdm.model.term.FeatureTree;
25
import eu.etaxonomy.cdm.model.term.TermTree;
26
import eu.etaxonomy.cdm.model.term.TermTreeNode;
26 27
import eu.etaxonomy.cdm.model.term.TermType;
27 28
import eu.etaxonomy.cdm.model.term.TermVocabulary;
28 29

  
......
56 57
        while(iterator.hasNext()){
57 58
            Resource tree = iterator.next();
58 59
            String type = tree.getProperty(OwlUtil.propType).getString();
59
            FeatureTree featureTree = FeatureTree.NewInstance(TermType.getByKey(type));
60
            TermTree<Feature> featureTree = TermTree.NewInstance(TermType.getByKey(type));
60 61
            featureTree.setTitleCache(tree.getProperty(OwlUtil.propLabel).getString(), true);
61 62

  
62 63
            Resource rootNode = tree.getProperty(OwlUtil.propHasRootNode).getResource();
......
66 67
        }
67 68
    }
68 69

  
69
    private void createNode(FeatureNode parent, Statement nodeStatement, String treeLabel, Model model, StructureTreeOwlImportState state) {
70
    private <T extends DefinedTermBase> void createNode(TermTreeNode<T> parent, Statement nodeStatement, String treeLabel, Model model, StructureTreeOwlImportState state) {
70 71
        if(state.getConfig().getProgressMonitor().isCanceled()){
71 72
            return;
72 73
        }
......
85 86

  
86 87
        // import term
87 88
        UUID termUuid = UUID.fromString(termResource.getProperty(OwlUtil.propUuid).getString());
88
        DefinedTermBase term = getTermService().find(termUuid);
89
        T term = (T)getTermService().find(termUuid);
89 90
        if(term==null){
90
            term = OwlImportUtil.createTerm(termResource, this, model, state);
91
            term = getTermService().save(term);
91
            term = (T)OwlImportUtil.createTerm(termResource, this, model, state);
92
            getTermService().save(term);
92 93
            vocabulary.addTerm(term); // only add term if it does not already exist
93 94
        }
94 95

  
95 96
        getVocabularyService().saveOrUpdate(vocabulary);
96 97

  
97
        FeatureNode<?> childNode = parent.addChild(term);
98
        TermTreeNode<?> childNode = parent.addChild(term);
98 99

  
99 100
        state.getConfig().getProgressMonitor().worked(1);
100 101

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/out/OwlExportUtil.java
31 31
import eu.etaxonomy.cdm.model.reference.Reference;
32 32
import eu.etaxonomy.cdm.model.term.DefinedTerm;
33 33
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
34
import eu.etaxonomy.cdm.model.term.FeatureNode;
35
import eu.etaxonomy.cdm.model.term.FeatureTree;
36 34
import eu.etaxonomy.cdm.model.term.Representation;
37 35
import eu.etaxonomy.cdm.model.term.TermBase;
36
import eu.etaxonomy.cdm.model.term.TermTree;
37
import eu.etaxonomy.cdm.model.term.TermTreeNode;
38 38
import eu.etaxonomy.cdm.model.term.TermVocabulary;
39 39
import eu.etaxonomy.cdm.persistence.dto.TermDto;
40 40

  
......
259 259
        return mediaResource;
260 260
    }
261 261

  
262
    static Resource createFeatureTreeResource(FeatureTree featureTree, ICdmRepository repo, StructureTreeOwlExportState state) {
262
    static Resource createFeatureTreeResource(TermTree featureTree, ICdmRepository repo, StructureTreeOwlExportState state) {
263 263
        Resource featureTreeResource = getFeatureTreeResource(featureTree, state)
264 264
                .addProperty(OwlUtil.propUuid, featureTree.getUuid().toString())
265 265
                .addProperty(OwlUtil.propLabel, featureTree.getTitleCache())
......
267 267
                .addProperty(OwlUtil.propType, featureTree.getTermType().getKey())
268 268
                ;
269 269

  
270
        FeatureNode rootNode = featureTree.getRoot();
270
        TermTreeNode rootNode = featureTree.getRoot();
271 271

  
272 272
        Resource resourceRootNode = OwlExportUtil.createNodeResource(rootNode, false, repo, state);
273 273
        featureTreeResource.addProperty(OwlUtil.propHasRootNode, resourceRootNode);
......
277 277
        return featureTreeResource;
278 278
    }
279 279

  
280
    private static void addChildNode(FeatureNode parentNode, Resource parentResourceNode, ICdmRepository repo, StructureTreeOwlExportState state){
281
        List<FeatureNode> childNodes = parentNode.getChildNodes();
282
        for (FeatureNode child : childNodes) {
280
    private static void addChildNode(TermTreeNode parentNode, Resource parentResourceNode, ICdmRepository repo, StructureTreeOwlExportState state){
281
        List<TermTreeNode> childNodes = parentNode.getChildNodes();
282
        for (TermTreeNode child : childNodes) {
283 283
            // create node resource with term
284 284
            Resource nodeResource = OwlExportUtil.createNodeResource(child, false, repo, state);
285 285

  
......
290 290
        }
291 291
    }
292 292

  
293
    static Resource createNodeResource(FeatureNode node, boolean initFeatureTree, ICdmRepository repo, StructureTreeOwlExportState state) {
293
    static Resource createNodeResource(TermTreeNode<Feature> node, boolean initFeatureTree, ICdmRepository repo, StructureTreeOwlExportState state) {
294 294
        if(initFeatureTree){
295
            createFeatureTreeResource(node.getFeatureTree(), repo, state);
295
            createFeatureTreeResource(node.getGraph(), repo, state);
296 296
            return getNodeResource(node, state);
297 297
        }
298 298
        Resource nodeResource = getNodeResource(node, state)
......
333 333
        return state.getModel().createResource(OwlUtil.RESOURCE_MEDIA+media.getUuid().toString());
334 334
    }
335 335

  
336
    private static Resource getNodeResource(FeatureNode node, StructureTreeOwlExportState state) {
336
    private static Resource getNodeResource(TermTreeNode node, StructureTreeOwlExportState state) {
337 337
        return state.getModel().createResource(OwlUtil.RESOURCE_NODE + node.getUuid().toString());
338 338
    }
339 339

  
340
    private static Resource getFeatureTreeResource(FeatureTree featureTree, StructureTreeOwlExportState state) {
340
    private static Resource getFeatureTreeResource(TermTree featureTree, StructureTreeOwlExportState state) {
341 341
        return state.getModel().createResource(OwlUtil.RESOURCE_FEATURE_TREE+featureTree.getUuid().toString());
342 342
    }
343 343

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/out/StructureTreeOwlExport.java
20 20

  
21 21
import eu.etaxonomy.cdm.io.common.CdmExportBase;
22 22
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
23
import eu.etaxonomy.cdm.model.term.FeatureTree;
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.term.TermTree;
24 25

  
25 26
/**
26 27
 * @author pplitzner
......
48 49
                break;
49 50
            }
50 51
            state.getConfig().getProgressMonitor().worked(1);
51
            FeatureTree featureTree = getFeatureTreeService().load(uuid);
52
            TermTree<Feature> featureTree = getFeatureTreeService().load(uuid);
52 53
            Resource featureTreeResource = OwlExportUtil.createFeatureTreeResource(featureTree, this, state);
53 54
        }
54 55

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/out/SDDDocumentBuilder.java
78 78
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
79 79
import eu.etaxonomy.cdm.model.term.DefinedTerm;
80 80
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
81
<<<<<<< HEAD
82
=======
83
import eu.etaxonomy.cdm.model.term.TermTreeNode;
84
import eu.etaxonomy.cdm.model.term.TermTree;
85
>>>>>>> ref #6794 change FeatureTree to TermTree
86 81
import eu.etaxonomy.cdm.model.term.Representation;
87 82
import eu.etaxonomy.cdm.model.term.TermBase;
88 83
import eu.etaxonomy.cdm.model.term.TermTree;
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/owl/in/StructureTreeOwlImportTest.java
37 37
import eu.etaxonomy.cdm.io.descriptive.owl.in.StructureTreeOwlImportConfigurator;
38 38
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
39 39
import eu.etaxonomy.cdm.model.common.Language;
40
import eu.etaxonomy.cdm.model.description.Feature;
40 41
import eu.etaxonomy.cdm.model.media.Media;
41 42
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
42 43
import eu.etaxonomy.cdm.model.media.MediaUtils;
43 44
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
44 45
import eu.etaxonomy.cdm.model.term.DefinedTerm;
45 46
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
46
import eu.etaxonomy.cdm.model.term.FeatureNode;
47
import eu.etaxonomy.cdm.model.term.FeatureTree;
48 47
import eu.etaxonomy.cdm.model.term.Representation;
48
import eu.etaxonomy.cdm.model.term.TermTree;
49
import eu.etaxonomy.cdm.model.term.TermTreeNode;
49 50
import eu.etaxonomy.cdm.model.term.TermType;
50 51
import eu.etaxonomy.cdm.model.term.TermVocabulary;
51 52
import eu.etaxonomy.cdm.persistence.dto.TermDto;
......
95 96
        this.endTransaction();
96 97

  
97 98
        String treeLabel = "test_structures";
98
        List<FeatureTree> trees = featureTreeService.listByTitle(FeatureTree.class, treeLabel, MatchMode.EXACT, null, null, null, null, null);
99
        List<TermTree> trees = featureTreeService.listByTitle(TermTree.class, treeLabel, MatchMode.EXACT, null, null, null, null, null);
99 100
        List<String> nodeProperties = new ArrayList<>();
100 101
        nodeProperties.add("term");
101 102
        nodeProperties.add("term.media");
102
        FeatureTree tree = featureTreeService.loadWithNodes(trees.iterator().next().getUuid(), null, nodeProperties);
103
        TermTree<Feature> tree = featureTreeService.loadWithNodes(trees.iterator().next().getUuid(), null, nodeProperties);
103 104
        assertNotNull("featureTree should not be null", tree);
104 105

  
105 106
        assertEquals("Tree has wrong term type", TermType.Structure, tree.getTermType());
106
        assertEquals("Wrong number of distinct features", 4, tree.getDistinctFeatures().size());
107
        assertEquals("Wrong number of distinct features", 4, tree.getDistinctTerms().size());
107 108
        List rootChildren = tree.getRootChildren();
108 109
        assertEquals("Wrong number of root children", 1, rootChildren.size());
109 110
        Object entirePlant = rootChildren.iterator().next();
110
        assertTrue("Root is no feature node", entirePlant instanceof FeatureNode);
111
        assertEquals("Root node has wrong term type", TermType.Structure, ((FeatureNode)entirePlant).getTermType());
112
        FeatureNode<DefinedTerm> entirePlantNode = (FeatureNode<DefinedTerm>) entirePlant;
113
        List<FeatureNode<DefinedTerm>> childNodes = entirePlantNode.getChildNodes();
111
        assertTrue("Root is no feature node", entirePlant instanceof TermTreeNode);
112
        assertEquals("Root node has wrong term type", TermType.Structure, ((TermTreeNode)entirePlant).getTermType());
113
        TermTreeNode<DefinedTerm> entirePlantNode = (TermTreeNode<DefinedTerm>) entirePlant;
114
        List<TermTreeNode<DefinedTerm>> childNodes = entirePlantNode.getChildNodes();
114 115
        assertEquals("Wrong number of children", 2, childNodes.size());
115 116

  
116 117
        String inflorescenceLabel = "inflorescence";
......
120 121
        DefinedTerm inflorescence = records.iterator().next();
121 122
        assertEquals(inflorescenceLabel, inflorescence.getLabel(Language.ENGLISH()));
122 123

  
123
        for (FeatureNode<DefinedTerm> featureNode : childNodes) {
124
        for (TermTreeNode<DefinedTerm> featureNode : childNodes) {
124 125
            assertTrue("Child node not found. Found node with term: "+featureNode.getTerm().getLabel(),
125 126
                    featureNode.getTerm().getUuid().equals(inflorescence.getUuid())
126 127
                    || featureNode.getTerm().getLabel(Language.ENGLISH()).equals("Flower"));
......
182 183
        this.endTransaction();
183 184

  
184 185
        String treeLabel = "properties 1.0";
185
        List<FeatureTree> trees = featureTreeService.listByTitle(FeatureTree.class, treeLabel, MatchMode.EXACT, null, null, null, null, null);
186
        List<TermTree> trees = featureTreeService.listByTitle(TermTree.class, treeLabel, MatchMode.EXACT, null, null, null, null, null);
186 187
        List<String> nodeProperties = new ArrayList<>();
187 188
        nodeProperties.add("term");
188
        FeatureTree tree = featureTreeService.loadWithNodes(trees.iterator().next().getUuid(), null, nodeProperties);
189
        TermTree tree = featureTreeService.loadWithNodes(trees.iterator().next().getUuid(), null, nodeProperties);
189 190
        assertNotNull("featureTree should not be null", tree);
190 191

  
191 192
        assertEquals("Tree has wrong term type", TermType.Property, tree.getTermType());
192
        assertEquals("Wrong number of distinct features", 12, tree.getDistinctFeatures().size());
193
        assertEquals("Wrong number of distinct features", 12, tree.getDistinctTerms().size());
193 194
        List rootChildren = tree.getRootChildren();
194 195

  
195 196
        String vocLabel = "Plant Glossary Properties";
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/ITermTree.java
1
/**
2
* Copyright (C) 2019 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.model.term;
10

  
11
import java.util.List;
12

  
13
/**
14
 * @author a.mueller
15
 * @since 11.03.2019
16
 */
17
public interface ITermTree<TERM extends DefinedTermBase, REL extends TermRelationBase>
18
            extends ITermGraph<TERM, REL> {
19

  
20
    /**
21
     * Returns the (ordered) list of {@link TermTreeNode feature nodes} which are immediate
22
     * children of the root node of <i>this</i> term tree.
23
     */
24
    public abstract List<TermTreeNode<TERM>> getRootChildren();
25

  
26
    public List<TERM> asTermList();
27

  
28
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)