Project

General

Profile

Revision e54a5a27

IDe54a5a27bea3251f48c1350e401ea7fa36fef9a5
Parent 15957179
Child 35e24b22

Added by Patrick Plitzner over 2 years ago

ref #8248, #6774 Add progress monitor to import/export

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/in/StructureTreeOwlImport.java
67 67
    }
68 68

  
69 69
    private void createNode(FeatureNode parent, Statement nodeStatement, String treeLabel, Model model, StructureTreeOwlImportState state) {
70
        if(state.getConfig().getProgressMonitor().isCanceled()){
71
            return;
72
        }
70 73
        Resource nodeResource = model.createResource(nodeStatement.getObject().toString());
71 74

  
72 75
        Resource termResource = nodeResource.getPropertyResourceValue(OwlUtil.propHasTerm);
......
93 96

  
94 97
        FeatureNode<?> childNode = parent.addChild(term);
95 98

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

  
96 101
        nodeResource.listProperties(OwlUtil.propHasSubStructure).forEachRemaining(prop->createNode(childNode, prop, treeLabel, model, state));
97 102
    }
98 103

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/in/TermVocabularyOwlImport.java
9 9
package eu.etaxonomy.cdm.io.descriptive.owl.in;
10 10

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

  
14 15
import org.springframework.stereotype.Component;
......
19 20
import com.hp.hpl.jena.rdf.model.Statement;
20 21
import com.hp.hpl.jena.rdf.model.StmtIterator;
21 22

  
23
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
22 24
import eu.etaxonomy.cdm.io.common.CdmImportBase;
23 25
import eu.etaxonomy.cdm.io.descriptive.owl.OwlUtil;
24 26
import eu.etaxonomy.cdm.model.media.Media;
......
51 53

  
52 54
        state.getModel().read(source.toString());
53 55

  
56
        //calculate total work
57
        int nodeCount = state.getModel().listResourcesWithProperty(OwlUtil.propIsA, OwlUtil.NODE).toSet().size();
58
        int termCount = state.getModel().listResourcesWithProperty(OwlUtil.propIsA, OwlUtil.TERM).toSet().size();
59
        int totalWork = nodeCount+termCount;
60
        IProgressMonitor progressMonitor = state.getConfig().getProgressMonitor();
61
        progressMonitor.beginTask("Importing terms", totalWork);
62

  
54 63
        //get all vocabularies
55 64
        ResIterator iterator = state.getModel().listResourcesWithProperty(OwlUtil.propIsA, OwlUtil.VOCABULARY);
56 65
        while(iterator.hasNext()){
......
65 74
            }
66 75

  
67 76
            // import terms
68
            StmtIterator termIterator = voc.listProperties(OwlUtil.propHasTerm);
69
            while(termIterator.hasNext()){
70
                createTerm(vocabulary, termIterator.next(), state.getModel(), state);
77
            Set<Statement> terms = voc.listProperties(OwlUtil.propHasTerm).toSet();
78
            for (Statement statement : terms) {
79
                if(progressMonitor.isCanceled()){
80
                    break;
81
                }
82
                createTerm(vocabulary, statement, state.getModel(), state);
83
                progressMonitor.worked(1);
71 84
            }
72 85

  
73 86
            getVocabularyService().saveOrUpdate(vocabulary);
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/out/StructureTreeOwlExport.java
48 48
        // export feature trees
49 49
        List<UUID> featureTreeUuids = state.getConfig().getFeatureTreeUuids();
50 50
        for (UUID uuid : featureTreeUuids) {
51
            if(state.getConfig().getProgressMonitor().isCanceled()){
52
                break;
53
            }
51 54
            state.getConfig().getProgressMonitor().worked(1);
52 55
            exportTree(uuid, state);
53 56
        }
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/owl/out/TermVocabularyOwlExport.java
9 9
package eu.etaxonomy.cdm.io.descriptive.owl.out;
10 10

  
11 11
import java.io.File;
12
import java.util.Collection;
13 12
import java.util.List;
14 13
import java.util.Set;
15 14
import java.util.UUID;
......
54 53

  
55 54
        // export term vocabularies
56 55
        for (UUID uuid : vocabularyUuids) {
56
            if(progressMonitor.isCanceled()){
57
                break;
58
            }
57 59
            progressMonitor.worked(1);
58 60
            exportVocabulary(uuid, state);
59 61
        }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)