Project

General

Profile

Revision 86244fd8

ID86244fd8522f06a7873a87f0c70741e46668d93a
Parent 7665d3d5
Child 2fa45f7e

Added by Katja Luther about 3 years ago

ref #6627: use taxonnodeFilter and partitioner for cdmLightExport

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/cdmLight/CdmLightClassificationExport.java
22 22
import org.springframework.stereotype.Component;
23 23

  
24 24
import eu.etaxonomy.cdm.common.CdmUtils;
25
import eu.etaxonomy.cdm.filter.LogicFilter;
25
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
26 26
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
27 27
import eu.etaxonomy.cdm.io.common.CdmExportBase;
28 28
import eu.etaxonomy.cdm.io.common.ExportResult.ExportResultState;
29 29
import eu.etaxonomy.cdm.io.common.ICdmExport;
30
import eu.etaxonomy.cdm.io.common.TaxonNodeOutStreamPartitioner;
31
import eu.etaxonomy.cdm.io.common.XmlExportState;
30 32
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
31 33
import eu.etaxonomy.cdm.model.agent.AgentBase;
32 34
import eu.etaxonomy.cdm.model.agent.Person;
......
71 73
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
72 74
import eu.etaxonomy.cdm.model.reference.Reference;
73 75
import eu.etaxonomy.cdm.model.reference.ReferenceType;
74
import eu.etaxonomy.cdm.model.taxon.Classification;
75 76
import eu.etaxonomy.cdm.model.taxon.Synonym;
76 77
import eu.etaxonomy.cdm.model.taxon.Taxon;
77 78
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
......
107 108
    @Override
108 109
    protected void doInvoke(CdmLightExportState state) {
109 110
        try {
111

  
112
            IProgressMonitor monitor = state.getConfig().getProgressMonitor();
110 113
            CdmLightExportConfigurator config = state.getConfig();
111 114
            config.setFieldsTerminatedBy(",");
112 115

  
113
            if (config.getTaxonNodeFilter().getTaxonNodesFilter().isEmpty() && config.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
114
                //TODO
115
                state.setEmptyData();
116
                return;
117
            }
118
            //TODO MetaData
119
            for (LogicFilter<Classification> classificationFilter : config.getTaxonNodeFilter().getClassificationFilter()){
120
                UUID classificationUuid = classificationFilter.getUuid();
121
                Classification classification = getClassificationService().find(classificationUuid);
122
                if (classification == null){
123
                    String message = String.format("Classification for given classification UUID not found. No data imported for %s", classificationUuid.toString());
124
                    state.getResult().addWarning(message);
125
                }else{
126
                    TaxonNode root = classification.getRootNode();
127
                    UUID uuid = root.getUuid();
128
                    root = getTaxonNodeService().load(uuid);
129
                    handleSingleClassification(state, root.getUuid());
116
//            if (config.getTaxonNodeFilter().getTaxonNodesFilter().isEmpty() && config.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
117
//                //TODO
118
//                state.setEmptyData();
119
//                return;
120
//            }
121

  
122

  
123

  
124
//            for (LogicFilter<Classification> classificationFilter : config.getTaxonNodeFilter().getClassificationFilter()){
125
//                UUID classificationUuid = classificationFilter.getUuid();
126
//                Classification classification = getClassificationService().find(classificationUuid);
127
//                if (classification == null){
128
//                    String message = String.format("Classification for given classification UUID not found. No data imported for %s", classificationUuid.toString());
129
//                    state.getResult().addWarning(message);
130
//                }else{
131
//                    TaxonNode root = classification.getRootNode();
132
//                    UUID uuid = root.getUuid();
133
//                    root = getTaxonNodeService().load(uuid);
134
//                    handleSingleClassification(state, root.getUuid());
135
//                }
136
//            }
137

  
138

  
139
            @SuppressWarnings("unchecked")
140
            TaxonNodeOutStreamPartitioner<XmlExportState> partitioner
141
              = TaxonNodeOutStreamPartitioner.NewInstance(
142
                    this, state, state.getConfig().getTaxonNodeFilter(),
143
                    100, monitor, null);
144

  
145

  
146
                monitor.subTask("Start partitioning");
147

  
148
                TaxonNode node = partitioner.next();
149
                while (node != null){
150
                  handleTaxonNode(state, node.getUuid());
151
                  node = partitioner.next();
130 152
                }
131
            }
132 153

  
133
            for (LogicFilter<TaxonNode> taxonNodeFilter : config.getTaxonNodeFilter().getTaxonNodesFilter()){
134
                UUID nodeUuid = taxonNodeFilter.getUuid();
135
                handleSingleClassification(state, nodeUuid);
136
            }
154

  
155
//            for (LogicFilter<TaxonNode> taxonNodeFilter : config.getTaxonNodeFilter().getTaxonNodesFilter()){
156
//                UUID nodeUuid = taxonNodeFilter.getUuid();
157
//                handleSingleClassification(state, nodeUuid);
158
//            }
137 159
            state.getProcessor().createFinalResult(state);
138 160
        } catch (Exception e) {
139 161
            state.getResult().addException(e, "An unexpected error occurred in main method doInvoke() " +
......
145 167
     * @param state
146 168
     * @param classificationUuid
147 169
     */
148
    private void handleSingleClassification(CdmLightExportState state, UUID taxonNodeUuid) {
170
    private void handleTaxonNode(CdmLightExportState state, UUID taxonNodeUuid) {
149 171
        try {
150 172
            TaxonNode taxonNode = getTaxonNodeService().find(taxonNodeUuid);
151 173

  
......
217 239
       }
218 240

  
219 241
       taxonNode.removeNullValueFromChildren();
220
       for (TaxonNode child: taxonNode.getChildNodes()){
221
           handleTaxon(state, child);
222
       }
242
//       for (TaxonNode child: taxonNode.getChildNodes()){
243
//           handleTaxon(state, child);
244
//       }
223 245

  
224 246
    }
225 247

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/TaxonNodeOutStreamPartitioner.java
27 27
 * @author a.mueller
28 28
 * @created 01.07.2017
29 29
 */
30
public class TaxonNodeOutStreamPartitioner<STATE extends XmlExportState> {
30
public class TaxonNodeOutStreamPartitioner<STATE extends IoStateBase> {
31 31

  
32 32
    private static final Logger logger = Logger.getLogger(TaxonNodeOutStreamPartitioner.class);
33 33

  
34 34
//************************* STATIC ***************************************************/
35 35

  
36 36
	public static <ST  extends XmlExportState>  TaxonNodeOutStreamPartitioner NewInstance(
37
	        ICdmRepository repository, XmlExportState state,
37
	        ICdmRepository repository, IoStateBase state,
38 38
            TaxonNodeFilter filter, Integer partitionSize,
39 39
            IProgressMonitor parentMonitor, Integer parentTicks){
40 40
		TaxonNodeOutStreamPartitioner<ST> taxonNodePartitioner

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)