Project

General

Profile

Revision c20ddc4e

IDc20ddc4e1bee08130e8849556715d5cd94b08717
Parent 51c10665
Child 4d025474

Added by Patrick Plitzner over 1 year ago

ref #8248 Implement termvocabulary import

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/in/StructureTreeOwlImportConfigurator.java
47 47
    @Override
48 48
    protected void makeIoClassList() {
49 49
        ioClassList = new Class[] {
50
                TermVocabularyOwlImport.class,
50 51
                StructureTreeOwlImport.class
51 52
        };
52 53
    }
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/in/TermVocabularyOwlImport.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.io.descriptive.owl.in;
10

  
11
import java.net.URI;
12
import java.util.UUID;
13

  
14
import org.springframework.stereotype.Component;
15

  
16
import com.hp.hpl.jena.rdf.model.Model;
17
import com.hp.hpl.jena.rdf.model.ResIterator;
18
import com.hp.hpl.jena.rdf.model.Resource;
19
import com.hp.hpl.jena.rdf.model.Statement;
20
import com.hp.hpl.jena.rdf.model.StmtIterator;
21

  
22
import eu.etaxonomy.cdm.io.common.CdmImportBase;
23
import eu.etaxonomy.cdm.io.descriptive.owl.OwlUtil;
24
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
25
import eu.etaxonomy.cdm.model.term.TermVocabulary;
26

  
27
/**
28
 *
29
 * @author pplitzner
30
 * @since May 27, 2019
31
 *
32
 */
33
@Component("structureTreeOwlImport")
34
public class TermVocabularyOwlImport extends CdmImportBase<StructureTreeOwlImportConfigurator, StructureTreeOwlImportState> {
35

  
36
    private static final long serialVersionUID = -3659780404413458511L;
37

  
38
    static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(TermVocabularyOwlImport.class);
39

  
40

  
41
    @Override
42
    protected boolean doCheck(StructureTreeOwlImportState state) {
43
        logger.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
44
        return true;
45
    }
46

  
47
    @Override
48
    public void doInvoke(StructureTreeOwlImportState state) {
49
        URI source = state.getConfig().getSource();
50

  
51
        state.getModel().read(source.toString());
52

  
53
        //get all vocabularies
54
        ResIterator iterator = state.getModel().listResourcesWithProperty(OwlUtil.propIsA, OwlUtil.VOCABULARY);
55
        while(iterator.hasNext()){
56
            Resource voc = iterator.next();
57
            String type = voc.getProperty(OwlUtil.propType).getString();
58

  
59
            UUID vocUuid = UUID.fromString(voc.getProperty(OwlUtil.propUuid).getString());
60
            TermVocabulary vocabulary = getVocabularyService().load(vocUuid);
61
            if(vocabulary==null){
62
                vocabulary = OwlImportUtil.createVocabulary(voc, getTermService(), state.getModel(), state);
63
                getVocabularyService().save(vocabulary);
64
            }
65

  
66
            // import terms
67
            StmtIterator termIterator = voc.listProperties(OwlUtil.propHasTerm);
68
            while(termIterator.hasNext()){
69
                createTerm(vocabulary, termIterator.next(), state.getModel(), state);
70
            }
71

  
72
            getVocabularyService().saveOrUpdate(vocabulary);
73

  
74
        }
75
    }
76

  
77
    private DefinedTermBase createTerm(TermVocabulary vocabulary, Statement termStatement, Model model, StructureTreeOwlImportState state) {
78
        Resource termResource = model.createResource(termStatement.getObject().toString());
79

  
80
        UUID termUuid = UUID.fromString(termResource.getProperty(OwlUtil.propUuid).getString());
81
        DefinedTermBase term = getTermService().load(termUuid);
82
        if(term==null){
83
            term = OwlImportUtil.createTerm(termResource, getTermService(), model, state);
84
            getTermService().saveOrUpdate(term);
85
        }
86
        vocabulary.addTerm(term);
87

  
88
        // check includes
89
        StmtIterator includesIterator = termResource.listProperties(OwlUtil.propTermIncludes);
90
        while(includesIterator.hasNext()){
91
            DefinedTermBase includeTerm = createTerm(vocabulary, includesIterator.next(), model, state);
92
            term.addIncludes(includeTerm);
93
        }
94
        // check generalization
95
        StmtIterator generalizationOfIterator = termResource.listProperties(OwlUtil.propTermIsGeneralizationOf);
96
        while(generalizationOfIterator.hasNext()){
97
            DefinedTermBase generalizationOfTerm = createTerm(vocabulary, generalizationOfIterator.next(), model, state);
98
            term.addGeneralizationOf(generalizationOfTerm);
99
        }
100
        return term;
101
    }
102

  
103
    @Override
104
    protected boolean isIgnore(StructureTreeOwlImportState state) {
105
        return false;
106
    }
107

  
108
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)